2

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.

Manjunath
  • 2,063
  • 2
  • 29
  • 60

2 Answers2

4

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);
}
Manjunath
  • 2,063
  • 2
  • 29
  • 60
1
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);
Linh Nguyen
  • 1,264
  • 1
  • 10
  • 22
  • I tried this, but I want the tab layout to be same as default. If I do this, it will remove the native tab background color. – Manjunath Aug 19 '13 at 13:46