Android unable to change background color of Actio

2019-07-20 12:34发布

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>

enter image description here

3条回答
唯我独甜
2楼-- · 2019-07-20 13:17
<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>
查看更多
The star\"
3楼-- · 2019-07-20 13:19

You can use this,

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#Color_Code")));
查看更多
老娘就宠你
4楼-- · 2019-07-20 13:21

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

查看更多
登录 后发表回答