使用滑动在 ActionBar 上设置图标 [英] Set icon on ActionBar using glide

查看:25
本文介绍了使用滑动在 ActionBar 上设置图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 glide 在回收站视图的图像视图中加载图像 URL,并且工作正常.

I am using glide to load image URLs in imageviews of recycler view and it works fine.

现在,我想从动态图像 URL 设置 ActionBar 图标.我如何使用 glide 实现它?

Now, I want to set ActionBar icon from a dynamic image URL. How can I achieve it using glide?.

我参考了以下链接:如何使用 glide 加载圆形 appcompat 操作栏徽标.但是,我没有得到结果.我不想切换到毕加索.

I have referred following link: How to load a circular appcompat actionbar logo using glide. But,I did not get the result. and I don't want to switch to picasso.

谁能帮帮我?

我的代码:

 Glide.with(this)
            .load(receiver1.profilepic)
            .placeholder(R.drawable.user)
            .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)
                {

                    Bitmap bitmap1=((GlideBitmapDrawable) resource).getBitmap();

                    Drawable drawable = new BitmapDrawable(getResources(), bitmap1);
                    actionBar.setIcon(drawable);
                }

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

                }
            });

推荐答案

首先,我们设置 getSupportActionBar().setDisplayShowHomeEnabled(true)getSupportActionBar().setDisplayUseLogoEnabled(true)code> 然后在管理操作栏图标可见性后,只需使用 actionBar.setIcon(bitmap)actionBar.setIcon(drawable) 来渲染加载的图像.

First, we set getSupportActionBar().setDisplayShowHomeEnabled(true) and getSupportActionBar().setDisplayUseLogoEnabled(true) and then after managing the action bar icon visibility, just use actionBar.setIcon(bitmap) or actionBar.setIcon(drawable) to render the loaded image.

这篇关于使用滑动在 ActionBar 上设置图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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