【问题标题】:Change background color of Tabs in ActionBar in Sherlocks library in Android?在 Android 的 Sherlocks 库中更改 ActionBar 中选项卡的背景颜色?
【发布时间】:2013-04-03 11:55:40
【问题描述】:

我正在使用 Sherlock 库开发 Actionbar。我想以不同的方式更改操作栏和选项卡的背景图像。目前我已经在运行时通过代码成功更改了操作栏的背景:

Drawable myIcon = getResources().getDrawable(R.drawable.blue_menu_background);
mActionBar.setBackgroundDrawable(myIcon);

但是我遇到了标签背景的问题。如何更改选项卡的背景。请给我建议。

【问题讨论】:

    标签: android tabs actionbarsherlock


    【解决方案1】:

    您可以使用此代码:

    actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor)); // for example new ColorDrawable(Color.BLUE)
    

    【讨论】:

    • 这不会改变每个标签的颜色。
    【解决方案2】:

    您可以使用 Style for Tabs 代替这样做:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
            <item name="android:actionBarTabTextStyle">@style/CustomTabTextStyle</item>
            <item name="android:actionBarDivider">@drawable/ab_divider</item>
            <item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
        </style>
    
        <!-- style for the action bar tab text -->
        <style name="CustomTabTextStyle" parent="@android:style/TextAppearance.Holo">
            <item name="android:textColor">#2456c2</item>
        </style>
    </resources>
    

    查看article了解更多详情。

    【讨论】:

      【解决方案3】:

      要更改操作栏选项卡的颜色,请使用以下代码:

      //例如如果你想要白色作为Tabs背景,那么

      getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
      

      【讨论】:

      • 你为什么需要重新发布答案?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 2017-04-24
      • 2015-07-25
      • 2015-08-14
      • 2022-12-19
      相关资源
      最近更新 更多