简体   繁体   English

更改Android 5.0 Actionbar颜色

[英]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. 我正在使用新的Lollipop Material Design指南,并希望将漂亮的导航抽屉动画合并到我的应用程序中。 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. 我已经通过使用android.support.v7.app.ActionBarDrawerToggle做到了这一点,但是现在我很难更改所述操作栏的颜色。 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>

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 . 根据AppCompat 的作者向v21迁移指南, AppCompat不会对Material Theme调色板项目使用android:前缀属性。 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 . 操作栏将由colorPrimary着色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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