如何设置FragmentTabHost
标签文字颜色。我尝试了下面的代码,但它没有用。
((TextView) mTabHost.getCurrentTabView()
.findViewById(android.R.id.title)).setTextColor(0xFFFFFFFF);
它让NPE说找不到TextView
。
答案 0 :(得分: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);
}
答案 1 :(得分: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);