3

How i can do that? is it possible?

:

tabhost.getTabWidget().getChildAt(i) . setTextColor or something else..?

lacas
  • 13,928
  • 30
  • 109
  • 183

3 Answers3

0

To change the text color of tabs, you need to get the view i.e TextView which is set as title of tabs and you can change it like this:

TabHost tabhost = getTabHost();
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
{
    TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
    tv.setTextColor(.....);
} 

hope this helps....

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
0

I guess you could use TabHost.TabSpec.setIndicator(android.view.View view) passing a TextView configured (colorized) according to your needs.

However I reread your post once again - probably you mean how to change the color of tab content, while I'm talking about tab label... If this is the case, I am sorry, please ignore this answer.

UPDATE:

It is most comfortable to do in your layout xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView 
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a tab - RED"
                android:textColor="#FF0000" />
            <TextView 
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is another tab - GREEN"
                android:textColor="#00FF00" />
            <TextView 
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a third tab - BLUE"
                android:textColor="#0000FF" />
        </FrameLayout>
    </LinearLayout>
</TabHost>
Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
0

Try ColorStateLists. Good Luck.

Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75