6

Possible Duplicate:
Android: Change Tab Text Color Programmatically

How can we change the text color in android tab.

Community
  • 1
  • 1
Altaf
  • 5,150
  • 10
  • 39
  • 55
  • The text color of what? You can use android:textColor on a TextView to set the color of text. A Tab must contain other views. – Robby Pond Mar 01 '11 at 13:57

2 Answers2

34

I use the ColorStateList, find it more elegant. Here is an example :

tab_text.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="@color/tab_active" />
    <item android:state_selected="false" android:color="@color/tab_inactive" />
</selector>

In your TextView, just set the textColor to point to this file with :

android:textColor="@color/tab_text"
isneesh
  • 436
  • 5
  • 5
21

You can use following code

    TabHost tabHost = getTabHost();
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
        { 
            TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
            tv.setTextColor(Color.parseColor("#ffffff"));
        } 
        TextView tv = (TextView) tabhost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
        tv.setTextColor(Color.parseColor("#000000"))
Tushar Vengurlekar
  • 7,649
  • 8
  • 33
  • 48