更改Sherlock TabBar的背景颜色



我正在尝试自定义SherlockTabBar,但一直在更改选项卡背景色。我已经使用了ActionBarStyle Generator,并从中复制了我感兴趣更改的资源。目前,我设法更改了选定的选项卡指示符,但我不知道如何更改选项卡背景和选项卡指示符。我的自定义样式代码如下:

  <style name="Theme.Custom" parent="style/Theme.Sherlock.Light">
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
  </style>
  <style name="MyActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar">
    <item name="android:background">@drawable/actionbarselector</item>
    <item name="android:gravity">center</item>
  </style>

和选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_customstyle"/>
  <item android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_customstyle" />
  <item android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_customstyle" />
</selector>

有什么建议吗?

感谢@Hemant提供线索,但您发布的代码将更改操作栏的背景颜色,而不是选项卡。但看到这些代码,我想到了以编程方式设置它,而不是按样式设置,如下所示:

SupportActionBar.SetStackedBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.ab_stacked_solid_customstyle));

再次感谢。

试试,这可以改变颜色。使用ARgb(#AARGGBB)生成"颜色"。Alpha(AA)表示透明或RGB(#RRGGBB)与标准颜色。

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF00853c")));

希望能奏效。。

最新更新