Android Text Tab Text Color

Possible duplicate:
Android: change text color tab programmatically

How to change text color on Android tab.

+6
android
source share
2 answers

You can use the 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")) 
+21
source share

I use 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 TextView, just set textColor to point to this file using

 android:textColor="@color/tab_text" 
+34
source share

All Articles