简体   繁体   中英

Android: Changing ActionBar background color Hex code

Okay so following Googles Developers guide I've tried (and failed) to change the color of the implemented actionbar. I'm currently using Android Studio instead of eclipse and have just updated everything to the recent release.

I'm essentially trying to change the color of the actionbar to anything but the default "light" color.

Here's some lovely code.

values/styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
    </style>

</resources>

values-v21/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar">
        <item name="android:background">#ff0000</item>
    </style>

</resources>

Any help appreciated thanks.

You can try this by coding if you want

ActionBar ab = getActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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