如何在菜单项中使用位图作为图标

时间:2019-04-19 15:45:04

标签: android xml bitmap menu icons

我似乎无法在菜单项中使用位图(特别是.png文件)作为图标,正确的方法是什么?

我尝试直接在xml中引用位图,但是还引用了本身在引用位图的BitMapDrawable xml。

navigation.xml bitmap_name中的项目是指位图或BitmapDrawable xml

<item
        android:id="@+id/id"
        android:icon="@drawable/bitmap_name"
        android:title="@string/title" />

BitmapDrawable xml。这里的bitmap_name是指位图。

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/bitmap_name">
</bitmap>

我希望位图显示为图标,但是我只会看到一个绿色的圆圈。 A image of the actual result

1 个答案:

答案 0 :(得分:0)

您可以将Ong文件直接放在可绘制文件夹中

enter image description here

然后,只需设置图标

<item
    android:id="@+id/id"
    android:icon="@drawable/error"
    android:title="@string/title"
    app:showAsAction="ifRoom"
 />

无需使用BitmapDrawable