如何设置FragmentTabHost
标签文本颜色。我尝试了下面的代码,但它不起作用。
如何设置FragmentTabHost标签文本颜色
((TextView) mTabHost.getCurrentTabView()
.findViewById(android.R.id.title)).setTextColor(0xFFFFFFFF);
它给NPE说它找不到TextView
。
如何设置FragmentTabHost
标签文本颜色。我尝试了下面的代码,但它不起作用。
如何设置FragmentTabHost标签文本颜色
((TextView) mTabHost.getCurrentTabView()
.findViewById(android.R.id.title)).setTextColor(0xFFFFFFFF);
它给NPE说它找不到TextView
。
这是一个有点棘手。我用下面的代码,它为我工作。
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(...)
然后setIndicator与您的自定义视图:
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator(view),
FragmentStackSupport.CountingFragment.class, null);
我试过这个,但我希望标签布局与默认相同。如果我这样做,它将删除本机选项卡背景颜色。 – Manjunath
转寄此这可以对你有用.. [变更标签彩色] [1] [1]:http://stackoverflow.com/questions/7783157/ android-text-and-color-on-tabs-tab-layout –
请参考这篇文章:http://stackoverflow.com/a/14853097/874752 –