Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector tag in android

Tags:

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.

like image 974
Datta Avatar asked Jul 04 '11 10:07

Datta


People also ask

What is Selector tag android?

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.

What are Drawables in android?

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.

What is ColorStateList?

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.

What is stroke in android XML?

This is used to control the behavior of miter joins when the joins angle is sharp. This value must be >= 0.


1 Answers

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

like image 156
Blundell Avatar answered Nov 11 '22 11:11

Blundell