开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜