How i can create ColorStateList object?

Put your problem here if it does not fit any of the other categories.

How i can create ColorStateList object?

Postby x-files » Wed Feb 20, 2008 2:52 pm

How i can create ColorStateList object?

Public Constructors
public ColorStateList(int[][] states, int[] colors)

ColorStateList colorStete = new ColorStateList(new int[][]{???}, new int[] {Color.GRAY, Color.WHITE, Color.WHITE}).

What i can use as first parameter?
x-files
Developer
Developer
 
Posts: 44
Joined: Fri Jan 11, 2008 10:27 am

Top

Postby x-files » Wed Feb 20, 2008 3:19 pm

selected state - android.R.attr.state_selected,
focused state - android.R.attr.state_focused

1)normal state - ?
2)What is mean two-dimensional array for states?
x-files
Developer
Developer
 
Posts: 44
Joined: Fri Jan 11, 2008 10:27 am

Postby plusminus » Wed Feb 20, 2008 4:12 pm

Hello x-files,

without having a thought on how to do in java, doing it in xml looks easier:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <selector xmlns:android="http://schemas.android.com/apk/res/android">
  2.  
  3.    <item android:state_focused="true" android:color="@color/testcolor1"/>
  4.  
  5.    <item android:state_pressed="true" android:state_enabled="false" android:color="@color/testcolor2" />
  6.  
  7.    <item android:state_enabled="false" android:colore="@color/testcolor3" />
  8.  
  9.    <item android:state_active="true" android:color="@color/testcolor4" />
  10.  
  11.    <item android:color="@color/testcolor5"/>
  12.  
  13.  </selector>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby zeeshan » Tue Apr 22, 2008 7:21 am

Hello

how can we apply this selector on textView i want to apply it on text color ???
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby zeeshan » Tue Apr 22, 2008 8:30 am

any body can help me please
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby konic » Fri Oct 09, 2009 8:47 pm

OK,
it is at least one year post but the answer didn't come yet.
Here is how that XML (from plusminus) was supposed to be used in source code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ColorStateList cl = null;
  2. try {
  3. XmlResourceParser xpp = getResources().getXml(R.color.selector_txt);
  4. cl = ColorStateList.createFromXml(getResources(), xpp);
  5. } catch (Exception e) {}
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Obviously, it is res/color/selector_txt.xml
To use it in other XML is even easier:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:textColor="@color/selector_txt"
  2.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests