android中的Selector标签

Dat*_*tta 6 android

我正在处理主屏应用程序,我正在尝试对现有应用程序进行一些更改.我从Mydroid文件夹下载了代码.在分析我发现他们在XML文件中使用了选择器标签时,我无法理解他们在哪里使用它来实现其功能.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:drawable="@drawable/ic_launcher_allshow" />
    <item android:state_checked="true" android:drawable="@drawable/ic_launcher_allhide" />
</selector>
Run Code Online (Sandbox Code Playgroud)

它存在于res/drawable文件夹中.

Blu*_*ell 10

选择器标签基本上查找当时UI的状态并显示适当的图像.

当复选框处于状态时,此特定drawable用于复选框

 android:state_checked="false"
Run Code Online (Sandbox Code Playgroud)

(即未选中复选框时)

它使用这个图像:

 @drawable/ic_launcher_allshow
Run Code Online (Sandbox Code Playgroud)

因此,检查:

 android:state_checked="true"
Run Code Online (Sandbox Code Playgroud)

使用

 @drawable/ic_launcher_allhide
Run Code Online (Sandbox Code Playgroud)

看这里:

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

&

http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html