Change ActionBarSherlock background color

后端 未结 3 1003
天涯浪人
天涯浪人 2020-12-01 01:42

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

相关标签:
3条回答
  • 2020-12-01 01:52

    I just used

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

    It changed the background color. Hope it helps.

    0 讨论(0)
  • 2020-12-01 02:11

    The code mentioned by Jake Wharton is true. But when applying the code to the styles.xml may not work if you have minSDK<11 because android:actionBarStyle is supported in API-11+

    To solve that error:

    Make a folder of values-v11 in your res folder and create the XML file as mentioned above.

    0 讨论(0)
  • 2020-12-01 02:13

    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.

    0 讨论(0)
提交回复
热议问题