问题
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);
回答1:
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.
回答2:
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:
I just used below Code
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#00853c")));
it changed the bg color. Hope, it helps.
回答4:
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" >
回答5:
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.
回答6:
create the custom action-bar, then you will make the color change of action-bar Sherlock.....
来源:https://stackoverflow.com/questions/15865914/how-to-change-the-color-of-actionbar-actionbarsherlock