如何在XML中選擇,android:drawable
屬性是在級別列表XML中定義的一種drawables?
我正在定義層次列表XML本身的drawable,以避免定義許多小XML文件。Android從XML級別列表中選擇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>