creating the simple button selector in android

Step 1: Create an XML in the drawable folder and name it selected_item.xml (or any another name you want but to be suggestive). The code in this xml will be:

<shape android="http://schemas.android.com/apk/res/android" shape="rectangle"><br /> <solid color="#80000000"><br /> </solid></shape>



The color="#80000000" is transparent black.
Step 2: Create an XML again, in the drawable folder an name it not_selected.xml. The code in this xml will be:


<shape android="http://schemas.android.com/apk/res/android" shape="rectangle">
<solid color="#80ffffff">
</solid></shape>


The color="#80ffffff" is transparent white.

Step 3 Create an XML again :) in the drawable folder and name it button_selector.xml. The code in this xml will be:

<selector android="http://schemas.android.com/apk/res/android">
<item drawable="@drawable/selected" state_focused="false" state_pressed="true">
<item drawable="@drawable/not_selected">
</item></item></selector>


Step 4 In the xml file where you make the button put this:

android:background="@drawable/button_selector"

6 comments :

Anonymous said...

This website definitely has all of the information I
wanted concerning this subject and didn't know who to ask.

My webpage; designskala.Com

Anonymous said...

Based on my own experiences I am going to make five recommendations that I wish someone had made to me to help take
the fear out of fitness. We know because they have done so for millions of
other people. Remember; there is a difference between a fattening diet and a healthy diet.


Here is my web-site ... fun fitness tips and facts

Anonymous said...

I am now not sure the place you're getting your info, but good topic. I needs to spend a while finding out much more or figuring out more. Thank you for wonderful info I was in search of this info for my mission.

Also visit my blog post - cccam server

Anonymous said...

I am really loving the theme/design of your website.

Do you ever run into any browser compatibility issues?
A small number of my blog audience have complained about my blog not operating correctly in Explorer but looks great in Safari.
Do you have any solutions to help fix this problem?

my weblog :: satellite for free

Anonymous said...

Nice post. I was checking constantly this weblog and I'm impressed! Very useful information specially the last section :) I care for such information a lot. I used to be looking for this particular info for a long time. Thanks and best of luck.

Have a look at my webpage; click here

Stevennall said...

Thank you for taking the time to write such an informative post. Your blog is not only informative, but it is also very creative.
android app design company