我可以将Picasso的照片加载到操作栏吗?

man*_*eak 12 android picasso

我一直在广泛使用毕加索通过互联网检索图像到我的应用程序.现在,我遇到了一种情况,我需要将一个小图像检索到操作栏(就像标题文本旁边的徽标一样).

毕加索可以做到这一点吗?如果是这样,我该怎么做?

man*_*eak 21

我找到了一个使用Picasso Target类的解决方案,不需要自定义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)
           {
           }
       });
Run Code Online (Sandbox Code Playgroud)