gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:03:38 25 4
gpt4 key购买 nike

如何使用此类代码在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 中创建选项卡。我只是想知道在这种代码中是否可行。谢谢。

最佳答案

您是否尝试通过更改 res/values/themes.xml 中的标签栏样式来设置标签背景的样式?这是 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>

因为HoneyComb和pre-HoneyComb设备需要设置两次。要使用新主题,您还需要将以下内容添加到 list 文件的应用程序标签中。

android:theme="@style/Theme.test"

关于android - 如何在android中设置导航选项卡的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17438966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com