高级设置标题图标

Advanced set title icon

如何使用 java android 应用程序的系统框架设置来自 android.graphics.Bitmap object 的 activity 的标题图标?

((Activity)obj).getActionBar().setIcon(R.drawable.icon);

此方法不适用于 android.graphics.Bitmap

谢谢

我发现了这个:

Bitmap bitmap = _bitmap; ((Activity)obj).getActionBar().setIcon(new BitmapDrawable(bitmap));

ActionBar#setIcon() requires a Drawable as you correctly mentioned. To wrap a Bitmap in a Drawable you have to use a BitmapDrawable.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Bitmap bitmap = getBitmap(); // your Bitmap

    Drawable drawable = new BitmapDrawable(getResources(), bitmap);
    getSupportActionBar().setIcon(mipmapDrawable);

    getSupportActionBar().setDisplayShowHomeEnabled(true);
}