Possible Duplicate:
Android: Change Tab Text Color Programmatically
How can we change the text color in android tab.
Right-click the worksheet tab whose color you want to change. Choose Tab Color, and then select the color you want. The color of the tab changes, but not the color of the font. When you choose a dark tab color, the font switches to white, and when you choose a light color for the tab, the font switches to black.
Android TextView – Text Color. TextView Text Color – To change the color of text in TextView, you can set the color in layout XML file using textColor attribute or change the color dynamically in Kotlin file using setTextColor() method.
TabLayout is used to implement horizontal tabs. TabLayout is released by Android after the deprecation of ActionBar. TabListener (API level 21). TabLayout is introduced in design support library to implement tabs. Tabs are created using newTab() method of TabLayout class.
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"
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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With