无法在图层列表中绘制位图

Can't draw bitmap in layer-list

我正在尝试创建一个复合背景,添加 shape drawable 并从 Android Studio 的矢量资源中搜索图标。但它没有显示搜索图标,而是绘制了一些指示错误的内容。

这是我的可绘制文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:width="44dp" android:height="24dp" android:gravity="center">
        <shape android:shape="rectangle">
            <corners android:radius="@dimen/parcel_indicator_corner_radius"/>
            <solid android:color="@color/colorAccent"/>
        </shape>
    </item>
    <item android:gravity="center" android:width="24dp" android:height="24dp">
        <bitmap android:src="@drawable/ic_search_white_24dp" />
    </item>
</layer-list>

有人知道为什么搜索图标可能不可见吗?

问题在这里

为项目设置 android:drawable 属性 而不是设置 Bitmap

 <item android:gravity="center" android:width="24dp" android:height="24dp">
    <bitmap android:src="@drawable/ic_search_white_24dp" />
</item>

替换为

 <item
    android:width="24dp"
    android:height="24dp"
    android:drawable="@drawable/ic_search_white_24dp"
    android:gravity="center">

</item>

我无法添加评论,所以我会留下这个作为答案。

搜索图标不可见,因为您可能使用了矢量资源。 bitmap 标签用于位图,例如png.