我尝试使用以下代码段
从文件中添加图像作为工具栏徽标Picasso.with(toolbar.getContext())
.load(file)
.placeholder(R.drawable.ic_action_camera)
.error(R.drawable.ic_action_camera)
.transform(new CircleTransform())
.into(target);
目标是
target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Logger.d("HIYA", "onBitmapLoaded");
Bitmap b = Bitmap.createScaledBitmap(bitmap, 120, 120, false);
BitmapDrawable icon = new BitmapDrawable(toolbar.getResources(), b);
toolbar.setLogo(icon);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Logger.d("HIYA", "onBitmapFailed");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Logger.d("HIYA", "onPrepareLoad");
}
};
答案 0 :(得分:0)
尝试以下link
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) {
}
});
这对我有用。