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
368 views
in Technique[技术] by (71.8m points)

Change Android 5.0 Actionbar color

I'm working with the new Lollipop Material Design guidelines and would like to incorporate that nifty navigation drawer animation in my app. I've gotten that far, by using the android.support.v7.app.ActionBarDrawerToggle, but now I'm having difficulty changing the color of said action bar. It stays bright gray no matter what I set the theme to. How would one go about changing the color of the actionbar? This is what my app theme looks like:

//res/values/styles.xml
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:colorPrimary">@color/primaryDef</item>
    <item name="android:colorPrimaryDark">@color/primaryDarkDef</item>
    <item name="android:activatedBackgroundIndicator">@drawable/defbg</item>
    <item name="android:colorAccent">@color/primaryDef</item>
    <item name="android:navigationBarColor">@color/primaryDarkDef</item>

</style>

<style name="ActionBar" parent="android:Widget.ActionBar">
    <item name="android:background">@color/primaryDef</item>
</style>
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <item name="colorPrimary">@color/primaryDef</item>
    <item name="colorPrimaryDark">@color/primaryDarkDef</item>
    <item name="colorAccent">@color/primaryDef</item>

    <item name="android:navigationBarColor">@color/primaryDarkDef</item>
    <item name="android:activatedBackgroundIndicator">@drawable/defbg</item>
</style>

The Action Bar will be colored by colorPrimary.


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

...