How to load a circular appcompat actionbar logo using glide

馋奶兔 提交于 2019-12-21 06:18:14

问题


Till now I have done the following, if I omit the circular image creation part it works fine, but I must show a circular image in actionbar

here is what I have tried so far, any help will be highly appreciated

Glide.with(mContext)
                    .load(doctorDetailsList.get(0).getDoc_imgurl().replace("200x200", Measuredwidth + "x" + Measuredwidth))
                    .placeholder(R.drawable.no_image)
                    .override(Measuredwidth, Measuredwidth)
                    .into(new Target<GlideDrawable>()
                    {
                        @Override
                        public void onLoadStarted(Drawable placeholder)
                        {

                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable)
                        {

                        }

                        @Override
                        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation)
                        {
                            //  GlideDrawable dr = resource;
                            Bitmap bitmap = ((com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) resource).getBitmap();
                            String filename = doctorDetailsList.get(0).getDoc_imgurl().trim().substring(doctorDetailsList.get(0).getDoc_imgurl().trim().lastIndexOf("/") + 1);
                            filename = filename.replaceAll(".jpg", "");
                            int resID = getResources().getIdentifier(filename, "data", getPackageName());
                            Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), resID);

                            //Drawable d = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 200, 200, true));

                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), icon);
                            circularBitmapDrawable.setCircular(true);
                            // GlideDrawable gd = new GlideDrawable(resource,)

                            getSupportActionBar().setLogo(circularBitmapDrawable);
                        }

                        @Override
                        public void onLoadCleared(Drawable placeholder)
                        {

                        }

                        @Override
                        public void getSize(SizeReadyCallback cb)
                        {

                        }

                        @Override
                        public void setRequest(com.bumptech.glide.request.Request request)
                        {

                        }

                        @Override
                        public com.bumptech.glide.request.Request getRequest()
                        {
                            return null;
                        }

                        @Override
                        public void onStart()
                        {

                        }

                        @Override
                        public void onStop()
                        {

                        }

                        @Override
                        public void onDestroy()
                        {

                        }
                    });

回答1:


could not find a way, switched to Picasso and changed the code as following

  Picasso.with(mContext)
                    .load(doctorDetailsList.get(0).getDoc_imgurl())
                    .resize(120, 120)
                    .centerCrop()
                    .placeholder(R.drawable.no_image)
                    .into(new com.squareup.picasso.Target()
                    {
                        @Override
                        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)
                        {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), bitmap);
                            circularBitmapDrawable.setCircular(true);                             
                            getSupportActionBar().setLogo(circularBitmapDrawable);
                        }

                        @Override
                        public void onBitmapFailed(Drawable errorDrawable)
                        {

                        }

                        @Override
                        public void onPrepareLoad(Drawable placeHolderDrawable)
                        {

                        }
                    });


来源:https://stackoverflow.com/questions/38845508/how-to-load-a-circular-appcompat-actionbar-logo-using-glide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!