Using selector to change TextView text color

Posted by rafuru on Stack Overflow See other posts from Stack Overflow or by rafuru
Published on 2012-04-02T18:57:39Z Indexed on 2014/08/23 10:21 UTC
Read the original article Hit count: 224

Filed under:
|

I'm trying to use a TextView to define the style of a TabWidget on a tabhost.

I just created a selector for bgcolor and works fine, but i want to make a selector for textColor but the text color don't change:

This is my tab_text_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
     <item android:state_selected="true" android:color="@android:color/white" />
    <item android:state_focused="true" android:color="@android:color/white" />
    <item android:state_pressed="true" android:color="@android:color/white" />

</selector>

And this is the code when i'm trying to use on a textView:

TextView txtTab=new TextView(this);
        txtTab.setTextColor(R.drawable.tab_text_selector);
        txtTab.setBackgroundResource(R.drawable.tab_bg_selector);
        txtTab.setGravity(Gravity.CENTER);
        txtTab.setText("Agregar Idea");

I know the text color must be white in any case but it doesn't.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-widget