Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to Make A Drawable Selector

I feel like this is kind of a silly question, but here I go anyways. I have an image button, and I want to be able to change it's image everytime it is clicked. The API seems to say that the best way to go about doing this is to create xml resource in the drawable folder that contains a selector and values. However when I go to make a new android xml resource, there's no option for drawables. What am I missing?

like image 790
aamiri Avatar asked Apr 11 '11 16:04

aamiri


People also ask

What are selectors in Android?

A multiplexor of SelectableChannel objects. A selector may be created by invoking the open method of this class, which will use the system's default selector provider to create a new selector. A selector may also be created by invoking the openSelector method of a custom selector provider.

What is RES drawable 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 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

You can add this in Android Studio, use Right click on project structure -> New -> Drawable resource file. It should look like this:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_enabled="false"          android:drawable="@drawable/cell_top_selected" />     <item android:drawable="@drawable/cell_top" /> </selector> 
like image 180
James Avatar answered Sep 19 '22 03:09

James