2

如何设置FragmentTabHost标签文本颜色。我尝试了以下代码,但是没有用。

((TextView) mTabHost.getCurrentTabView()
                .findViewById(android.R.id.title)).setTextColor(0xFFFFFFFF);


它给 NPE 说它找不到TextView.

4

2 回答 2

4

这有点棘手。我使用了以下代码,它对我有用。

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);
}
于 2013-08-20T07:29:51.413 回答
1
let's try this :
for example when you add your tab make your Indicator  : 

    TextView view = ....
    vew.setTextColor(...)

然后 setIndicator 与您的自定义视图:

 mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator(view),
                    FragmentStackSupport.CountingFragment.class, null);
于 2013-08-19T13:43:42.420 回答