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.
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.
android.content.res.ColorStateList. Lets you map View state sets to colors. ColorStateList s are created from XML resource files defined in the "color" subdirectory directory of an application's resource directory. The XML file contains a single "selector" element with a number of "item" elements inside.
This is used to control the behavior of miter joins when the joins angle is sharp. This value must be >= 0.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With