我可以将Picasso的图片加载到操作栏上吗? [英] Can I load a picture with Picasso to the action bar?
本文介绍了我可以将Picasso的图片加载到操作栏上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在广泛使用 Picasso 来通过Internet将图像检索到我的应用程序.现在,我遇到了一种情况,我需要在操作栏中检索一个小图像(例如标题文本旁边的徽标).
I've been using Picasso extensively to retrieve images over the internet to my app. Now, I've run into a situation where I need to retrieve a small image to the action bar (like a logo next to the title text).
是否可以用毕加索做到这一点?如果是这样,我该怎么办?
Is it possible to do this with Picasso? If so, how would I do that?
推荐答案
我找到了一个使用Picasso的Target
类并且不需要自定义操作栏的解决方案.
I found out a solution which uses Picasso's Target
class and does not require a custom Action Bar.
final ActionBar ab = getSupportActionBar();
Picasso.with(this)
.load(imageURL)
.into(new Target()
{
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)
{
Drawable d = new BitmapDrawable(getResources(), bitmap);
ab.setIcon(d);
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayHomeAsUpEnabled(true);
}
@Override
public void onBitmapFailed(Drawable errorDrawable)
{
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable)
{
}
});
这篇关于我可以将Picasso的图片加载到操作栏上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文