Android unable to change background color of ActionBar

六月ゝ 毕业季﹏ 提交于 2020-01-15 08:57:08

问题


I'm trying to change the background color of my Actionbar, but after referencing the several other questions on this site I still can't get their solutions to work.

Styles.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarStyle">@style/ActionBar</item>
        <item name="android:windowActionBar">true</item>
    </style>

    <style name="ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
        <item name="background">@color/light_blue_menu_bar</item>
    </style>
</resources>

colors.xml

<resources>
    ... 
    <color name="blue_semi_transparent_pressed">#80738ffe</color>
    <color name="light_blue_menu_bar">#87CEFA</color>
</resources>

manifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

However the ActionBar doesn't appear in of my views. What am I missing?

EDIT

The solution was to add to styles.xml

<item name="android:windowActionBar">true</item>


回答1:


<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    <item name="actionBarStyle">@style/ActionBarStyle</item>
    <item name="android:windowActionBar">true</item>
</style>

<style name="ActionBarStyle" parent="Widget.AppCompat.ActionBar">
        <item name="background">@color/blue</item>
    <item name="android:background">@color/blue</item>
</style>



回答2:


You can use this,

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



回答3:


Maybe you should edit styles.xml at values-v14 folder.Because your min version is 19.



来源:https://stackoverflow.com/questions/30227516/android-unable-to-change-background-color-of-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!