简体   繁体   中英

How to set FragmentTabHost tab text color

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM