Android: Change Tab Text Color Programmatically

后端 未结 4 1701
星月不相逢
星月不相逢 2020-11-30 09:08

I\'ve a TabHost like this:


 

        
4条回答
  •  星月不相逢
    2020-11-30 09:33

    For me @Farhan 's solution did not work since getChildCount() kept returning 1 while having four tabs. Using getTabCount() and getChildTabViewAt() solved it for me:

    for (int tabIndex = 0 ; tabIndex < mTabHost.getTabWidget().getTabCount() ; tabIndex ++) {
        View tab = mTabHost.getTabWidget().getChildTabViewAt(tabIndex);
        TextView t = (TextView)tab.findViewById(android.R.id.title);
        t.setTextColor(getResources().getColor(R.color.white));
    }
    

    I'd thought I post this alternative for people having the same issue.

提交回复
热议问题