Pregunta

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.

¿Fue útil?

Solución

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);
}

Otros consejos

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top