How to use and create a ColorStateList object???

by Mikael Bertlin » Mon, 19 Oct 2009 13:35:34 GMT

Sponsored Links
 Hi, I'm trying to set a get a ColorStateList object from a xml file
and setting it to a TextView textColor but I can't get it to work.


ColorStateList csl = null;

                 XmlResourceParser xpp=Resources.getSystem().getXml
                     try {
                                csl = 
ColorStateList.createFromXml(getResources(), xpp);
                        } catch (XmlPullParserException e) {
                                // TODO Auto-generated catch block
                        } catch (IOException e) {
                                // TODO Auto-generated catch block

                 final TextView tv = (TextView) findViewById(;

in res/color/sector_txt.xml
<selector xmlns:android="" ;>
   <item android:state_pressed="true" android:textColor="#FF004F79"/>
   <item android:state_pressed="false" android:textColor="#FF19AEFF"/>


The TextVew comes from my layout xml of a ListView Im using it in.
When I use the above code my app crashes.

How to I use the ColorStateList?
Have I set it correctly?
Where do I find the different states I can use in the xml?


Other Threads

1. Is there a flag I can enable to permanently display the virtual keyboard in my app?

I want to permanently display the virtual keyboard in my application,
but it seems bound by focus to an edit text field.  Is there a way
around this?



2. How to set selection of editText by using SendKeyEvent function of InputConnection class

I need to set selection of an editText box via InputConnection. I used
the SendKeyEvent function with the KEYCODE_DPAD_LEFT and META_SHIFT_ON
state but I've had no luck. My code is as below:

// I've already received hardware key event of DPAD left key as event
parameter in this function.

// Change the meta state of event parameter to META_SHIFT_ON
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
                        event.getAction(), event.getKeyCode(), 
                        event.getDeviceId(), event.getScanCode());
InputConnection ic = getCurrentInputConnection();

After excuting the code, there still no selection in the EditText.

Could somebody help me to resolve this ?

Thanks in advance.


3. ScaleAnimation problem

4. Desktop API of Gears API does not work on Android browser for 1.5

5. AudioRecord can't get any notification when record/marker position updated

6. Can not read apk file on android emulator - SDK 1.1

7. How to setup Access Point parameters programmatically