Change clickable TextView's color on focus and click?

If you want to set stateful color from code, you need to pass in ColorStateList as an argument to setTextColor passing an int to the method results in setting the color to all the states. It also looks like your xml is not totally correct. Example from ColorStateList docs looks like.

If you want to set stateful color from code, you need to pass in ColorStateList as an argument to setTextColor passing an int to the method results in setting the color to all the states. It also looks like your xml is not totally correct. Example from ColorStateList docs looks like: UPD on how to set a ColorStateList to text color: ColorStateList cl = null; try { XmlResourceParser xpp = getResources().

GetXml(R.color. Selector_txt); cl = ColorStateList. CreateFromXml(getResources(), xpp); } catch (Exception e) {} With XML its as easy as: android:textColor="@color/selector_txt.

I changed my XML file to what you suggested, and I did some searching on how I was supposed to send a ColorStateList in the setTextColor method. And I found this useful post: anddev. Org/post27828.

Html#p27828 So now it's all working correctly. :) However, I need to tweak the states a bit in the xml document. – Daniel Jonsson Mar 21 at 7:35 @Daniel Jonsson I've added the code from the post to the answer, so it would be easier for someone else.

– Konstantin Burov Mar 21 at 8:02.

Look in R. Java class (it's generated automatically). You have something like that: public static final class color { public static final int gray_transparent=0x7f050001; } So in your code in line: title.

SetTextColor(R.color. Textcolor); you're not setting values from textcolor. Xml but int from R.

Java (which contains textcolor. Xml address). The valid way to set color is: title.

SetTextColor(getResources(). GetColor(R.color. Textcolor)).

Thanks a lot for your help! Now it actually reads the colors from the file. :) However, I'm still having a problem.It just reads the default color.

The color won't change if I click on the text, which is strange. Do you know what causes this? – Daniel Jonsson Mar 20 at 23:14 1 It should be getResources().

GetColorStateList, not getResources().getColor. – Patrick Aug 9 at 16:49 @Patrick yeah, getResources(). GetColorStateList is really worked.

– anticafe 2 days ago.

Step 1:set the text color in xml like this android:textColor="@color/text_color" step2:And create res/color/text_color. Xml xml is.... then it will work fine Thank you.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions