I'm trying to change the TabWidget
text color, without success, even though I've tried different way to change it (see code below.)
My background tabs is an image:
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
}
I do not know if this creates some sort of conflict with what I want to do now.
Solution1:
main.xml
....
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tabbarbackground"
android:tabStripEnabled="false"
style="@style/TabText"
/> ....
style.xml
... <style name="TabText">
<item name="android:textColor">@color/tab_text_color</item> </style> ....
tab_text_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:textColor="#2daed9" />
<item android:state_selected="false" android:color="#FFFFFF" />
</selector>
solution 2
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
RelativeLayout rl = (RelativeLayout) tabHost.getTabWidget().getChildAt(i);
TextView textView = (TextView) rl.getChildAt(1);
textView.setTextColor(R.color.tab_text_color);
}
tab_text_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:textColor="#2daed9" />
<item android:state_selected="false" android:color="#FFFFFF" /> </selector>
but neither solution works.
However, if I change the second solution
textView.setTextColor (R.color.tab_text_color);
to
textView.setTextColor (Color.parseColor ("# ...."));
It works, except this solution does not change the color of text when I click on it.
Thanks.