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

标签 android

如何使用这种代码在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/

相关文章:

android - 试图了解需要将哪些 SHA-1(开发和发布)添加到 firebase android 项目

java - 需要帮助从 firebase 读取数据

android - 当应用程序处于后台/未运行时,不会在通知点击时打开特定 Activity

Android 中的 java TimeZone 和 TimeUnit 以及 SimpleDateFormat

Android:如何创建 TextInputLayout 的自定义 UI

java - 使用 Retrofit 从货币 API 获取每月数据

android - 如何在android中画一条线

android - 如何使我的项目与 getMapAsync 兼容?

android - 使用 MvvmCross 绑定(bind)到 layout_width 和 layout_height

java - 如何在事件调用后200ms触发方法?