Selector tag in android
I am working on the home screen application, where I am trying to do some changes to existing one. I downloaded code from Mydroid folder. And when analyzing that I found that they used开发者_如何转开发 selector tag in XML file, but I couldn't understand where exactly they used that to achieve its functionality.
<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>
It is present in res/drawable folder.
A selector tag basically looks for the state of the UI at the time and displays the appropriate image.
This particular drawable is for a check box, when the checkbox is in the state
android:state_checked="false"
(i.e. when the checkbox is not checked)
it uses this image:
@drawable/ic_launcher_allshow
Therefore , checked:
android:state_checked="true"
uses
@drawable/ic_launcher_allhide
See here:
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
&
http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html
精彩评论