作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何使用此类代码在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/
我是一名优秀的程序员,十分优秀!