Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中设置导航选项卡的背景色_Android - Fatal编程技术网

如何在android中设置导航选项卡的背景色

如何在android中设置导航选项卡的背景色,android,Android,如何用这种代码设置android中导航标签的背景色 ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab1 = bar.newTab(); ActionBar.Tab tab2 = bar.newTab();

如何用这种代码设置android中导航标签的背景色

            ActionBar bar = getSupportActionBar();
            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

            ActionBar.Tab tab1 = bar.newTab();
            ActionBar.Tab tab2 = bar.newTab();
            tab1.setText("Fragment A");
            tab2.setText("Fragment B");
            tab1.setTabListener(new MyTabListener());
            tab2.setTabListener(new MyTabListener());
            bar.addTab(tab1);
            bar.addTab(tab2);`

我没有用xml创建选项卡。我只是想知道这种代码是否可行。多谢各位

我正在考虑使用

我将首先查看另一篇SO帖子:但是,似乎您只能设置底部栏的整个背景色和颜色,而不能设置每个选项卡的颜色

否则,如果您想使用旧的skool,可以使用TabHost而不是ActionBar。这将允许您为每个特定选项卡设置颜色,并且您应该能够将它们的样式设置为类似于4.2ish操作栏的样式。”这很简单:

tabHost.getTabWidget().getChildAt(TAB_1_INDEX).setBackgroundResource(R.drawable.tab_1_inactive);
tabHost.getTabWidget().getChildAt(TAB_2_INDEX).setBackgroundResource(R.drawable.tab_2_inactive);
tabHost.getTabWidget().getChildAt(TAB_3_INDEX).setBackgroundResource(R.drawable.tab_3_inactive);
tabHost.getTabWidget().getChildAt(pos).setBackgroundResource(activeTabShape[pos]);

您是否尝试通过从res/values/themes.xml更改tabbar样式来设置选项卡背景的样式?下面是Theme.Sherlock.Light主题的示例

<style name="Theme.test" parent="@style/Theme.Sherlock.Light">
        <item name="android:actionBarTabBarStyle">@style/Theme.test.tabbar.style</item>
        <item name="actionBarTabBarStyle">@style/Widget.test.ActionBar.TabBar</item>
</style>

<style name="Theme.test.tabbar.style" parent="@style/Theme.Sherlock.Light.ActionBar">
    <item name="android:background">#00ff00</item>
    <item name="background">#00ff00</item>
</style>

<style name="Widget.test.ActionBar.TabBar" parent="Widget.Sherlock.Light.ActionBar.TabBar">
    <item name="android:background">#00ff00</item>
    <item name="background">#00ff00</item>
</style>

实际上,我正计划将整个背景设置到我的选项卡上。不是每个项目/选项卡。:)啊酷,那么我引用的那个页面有很多很好的资源。你应该检查一下,然后再投票给你喜欢的人试试这个
android:theme="@style/Theme.test"