如何使用滑行加载圆形appcompat操作栏徽标 [英] How to load a circular appcompat actionbar logo using glide

查看:71
本文介绍了如何使用滑行加载圆形appcompat操作栏徽标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经完成以下操作,如果我省略了圆形图像创建部分,它可以正常工作,但是我必须在操作栏中显示圆形图像

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()
                        {

                        }
                    });

推荐答案

找不到方法,切换到毕加索并按如下所示更改代码

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)
                        {

                        }
                    });

这篇关于如何使用滑行加载圆形appcompat操作栏徽标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆