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.

Code:

------------
ColorStateList csl = null;

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

                 final TextView tv = (TextView) findViewById(R.id.label);
                 tv.setTextColor(csl);
------------

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

------------

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?

thanks
/Micke
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Fwd: what will be the parameter of HttpGet httpget = new HttpGet("http://10.91.28.203");

so how to config device to access the internet


---------- Forwarded message ----------
From: Kostya Vasilyev <kmans...@gmail.com>
Date: Wed, May 18, 2011 at 4:37 PM
Subject: Re: [android-developers] what will be the parameter of HttpGet
httpget = new HttpGet("http://10.91.28.203");
To: android-developers@googlegroups.com


 18.05.2011 14:58, Rocky :

10.91.28.203 its not reachable , but localhost is reachable, while
www.google.com is also not reachable from adb shell


Then your device is not configured to access the Internet.


-- 
Kostya Vasilyev -- http://kmansoft.wordpress.com

 --




-- 
Thanks & Regards

Rakesh Kumar Jha
Software Developer
Symphony Services Corp (India) Pvt Ltd
Bangalore
(O) +918030274295
(R) +919886336619

-- 

2. "Using lunch master without the GUI. No such file: generic-eng." error during building of code

When I have given the build command "./build/envsetup.sh", everything is 
fine but when I have given "lunch generic-eng" command the following error 
appeared i.e. "Using lunch master without the GUI. No such file: 
generic-eng."

-- 

3. How to write TextView's text with multi color

4. 螒蟺: google-api-client + Buzz + OAuth2 + auth token

5. Root MyTouch 4G

6. list of receiver that i can a declare in manifest

7. Whether NeofreeRunner is compatible with android 2.3