繁体   English   中英

更改Sherlock TabBar背景色

[英]Change the Sherlock TabBar background color

我正在尝试自定义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(#AARRGGBB)生成颜色。 Alpha(AA)适用于具有标准颜色的透明度或RGB(#RRGGBB)。

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

希望能工作..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM