[英]How to set FragmentTabHost tab text color
如何設置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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.