是否可以在 drawable 中使用 XML 资源和 <shape>
属性?
因此,我有这个按钮。
<Button
android:layout_marginRight="5dp"
android:id="@+id/send_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/send_button" />
这里有一个名为send_button.xml的背景文件:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_send_white_48dp" android:state_focused="true"/>
<item android:drawable="@drawable/ic_send_white_48dp" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_send_black_48dp"/>
</selector>
目前这个工作得很好。但我还想在可绘制对象后面添加背景颜色和圆角,就像这样:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="4dp" />
<gradient
android:angle="270"
android:endColor="#88b823"
android:startColor="#b0dc54" />
</shape>
那么是否可以将这两个XML资源合并起来呢? 到目前为止我尝试的只是显示了drawable,但没有显示shape:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_send_white_48dp" android:state_focused="true"/>
<item android:drawable="@drawable/ic_send_white_48dp" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_send_black_48dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="4dp" />
<gradient android:angle="270"
android:endColor="#88b823"
android:startColor="#b0dc54" />
</shape>
</item>
</selector>