レベルリスト XML で定義されたドローアブルの 1 つをプロパティとしてXMLで選択するにはどうすればよいですか?
多数の小さな XML ファイルを定義することを避けるために、レベル リスト XML 自体でドローアブルを定義しています。android:drawable
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/empty"
android:endColor="@android:color/white"
android:angle="90" />
</shape>
</item>
<item android:maxLevel="1">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="@color/low"
android:endColor="@android:color/white"
android:angle="90" />
</shape>
</item>
<item android:maxLevel="2">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/middle"
android:endColor="@android:color/white"
android:angle="90" />
</shape>
</item>
<item android:maxLevel="3">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/high"
android:endColor="@android:color/white"
android:angle="90" />
</shape>
</item>
<item android:maxLevel="4">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/full"
android:endColor="@android:color/white"
android:angle="90" />
</shape>
</item>
</level-list>