How to change the color of actionbar (actionbarshe

2019-07-12 02:38发布

How to change the color of actionbar (actionbarsherlock) ?

I've been tried below code but no luck.

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
    <item name="background">#ffffffff</item>
</style>

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

+and one thing more, i'm add submenu like below. this button's background color is also white(because Sherlock Theme). could i change those colors?

    SubMenu sub = menu.add("abcd");
    sub.add(0, 1, 0, "Default");
    sub.add(0, 2, 0, "Light");
    sub.add(0, 3, 0, "Light (Dark Action Bar)");
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

6条回答
手持菜刀,她持情操
2楼-- · 2019-07-12 02:48

I think you should use @style/Widget.Sherlock.Light.ActionBar.Solid or @style/Widget.Sherlock.Light.ActionBar.Solid.Inverse as parent for ActionBarStyle and both attributes background and android:background. For example:

<style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
    <item name="background">#ffffff</item>
    <item name="android:background">#ffffff</item>
</style>

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

ActionBar style generator may help you with styling sub menus.

查看更多
唯我独甜
3楼-- · 2019-07-12 02:51

Use this style:

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
      <item name="background">#ffffffff</item>
      <item name="android:background">#ffffffff</item>
</style>

I assume you tested your application on a device with HC or above, and since you didn't specify a background for the native ActionBar, it did not work. Change it the the style above and it should work.

查看更多
甜甜的少女心
4楼-- · 2019-07-12 02:54

create the custom action-bar, then you will make the color change of action-bar Sherlock.....

查看更多
混吃等死
5楼-- · 2019-07-12 03:02

What you first posted looks almost exactly right, that is the theme that you need to add to change the ActionBar color. You should also add the android:background attribute with your color:

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
    <item name="background">#ffffffff</item>
    <item name="android:background">#ffffffff</item>
 </style>

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

However, you need to make sure you apply it either to your whole application, or just to the activity that you want to display it in. You can do this in either the application tag or the activity tag in AndroidManifest.xml with the android:theme attribute.

<application
    android:name="com.your.package.name"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.SherlockCustom" >
查看更多
戒情不戒烟
6楼-- · 2019-07-12 03:07
 I just used below Code 

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

 it changed the bg color. Hope, it helps.
查看更多
相关推荐>>
7楼-- · 2019-07-12 03:08

When it comes to styling the actionBar, the best shot you have is to use the very popular Action Bar Style Generator which is a web app that will let you preview the way the ActionBar will look, and let you download all the necessary assets to simply add it to your product: 9patches, state-drawables, and .xmls.

If you are not sure how to use that, here's a quick guide.

Using this is the best shot at making sure the action bar looks great, without wasting much of your time that could be best spent on valuable Java Code.

查看更多
登录 后发表回答