Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

android - Change ActionBarSherlock background color

I'm trying to implement ActionBarSherlock because I was told it is relatively easy to implement and customize. I've found it was pretty easy to implement, but I'm trying to change the background color of the ActionBar and it's proving difficult.

According to the the site (link), it seems you can inherit one of the ActionBarSherlock's themes and then override the properties you need.

This is what I have so far:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="Theme.ActionBar" parent="Theme.Sherlock.ForceOverflow">
      <item name="android:background">#000000</item>
      <item name="background">#000000</item>
    </style>
</resources>

I'm noticing the built-in theme are using images for the background, but I'm praying I don't have to create images to change the background color.

Thanks.

question from:https://stackoverflow.com/questions/10064411/change-actionbarsherlock-background-color

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The action bar background color is defined in a style for the action bar, not in the theme itself. You'll need to do something like this:

<style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverflow">
    <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
</style>

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

Be careful using colors defined in XML. ColorDrawable did not respect it's view bounds on pre-Honeycomb so if you use tab navigation with a separate background for the stacked tab view you will have problems.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...