如何以编程方式创建选项卡时设置选项卡文本颜色

时间:2014-02-09 22:28:41

标签: android colors tabs

我在没有tabhost的onCreate方法中创建了我的标签。如何以编程方式设置文本颜色?如果有帮助的话,这是一个相对布局,id = relativeLayoutTimeline。

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(true);
    Tab tabHome = actionBar.newTab().setText("Home").setTag("HomeTimelineFragment")
            .setIcon(R.drawable.home_icon).setTabListener(this);

2 个答案:

答案 0 :(得分:2)

傻迈克尔。你可以用这样的风格做得更好。

<!-- The theme for the activity -->
<style name="TabSpecialTheme" parent="android:Theme.Holo.Light.DarkActionBar">
  <item name="@android:attr/actionBarTabTextStyle">@style/TabStyle</item>
</style>

<!-- Modify the text color -->
<style name="TabStyle" parent="android:Widget.Holo.Light.ActionBar.TabText.Inverse">
  <item name="android:textColor">#F70000</item>
</style>

答案 1 :(得分:2)

另一种可能的解决方案是为标签文本创建TextView,为每个标签设置Customview属性。

TextView tView = new TextView(getActivity().getApplicationContext());
tView.setText(tab_name);
tView.setTextColor(Color.RED);  

actionBar.addTab(actionBar.newTab()  
                .setTabListener(this)
                .setCustomView(tView));
相关问题