Reputation: 2063
How to set FragmentTabHost
tab text color. I tried the following code but, it didn't work.
((TextView) mTabHost.getCurrentTabView()
.findViewById(android.R.id.title)).setTextColor(0xFFFFFFFF);
It gives NPE saying it couldn't find the TextView
.
Upvotes: 2
Views: 4586
Reputation: 2063
It was a bit tricky. I used the following code and it worked for me.
for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
final TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i)
.findViewById(android.R.id.title);
// Look for the title view to ensure this is an indicator and not a divider.(I didn't know, it would return divider too, so I was getting an NPE)
if (tv == null)
continue;
else
tv.setTextColor(0xFFFFFFFF);
}
Upvotes: 4
Reputation: 1264
let's try this :
for example when you add your tab make your Indicator :
TextView view = ....
vew.setTextColor(...)
then setIndicator with your custom view :
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator(view),
FragmentStackSupport.CountingFragment.class, null);
Upvotes: 1