Hello I am noob in Android.

I am using appcompat support library to make my application backward compatible. Here action bar color is Light by default I want to change the background color to my custom color.

Any idea how to do this ??

styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

enter image description here

有帮助吗?

解决方案

This solved my problem. Thanks @Zohra

ActionBar mActionBar = getActionBar();
mActionBar.setBackgroundDrawable(new ColorDrawable("COLOR"));

其他提示

You can try to use an approach from official documentation. I think it has clear example how to do it.

your style might look like this

reference:- https://developer.android.com/training/basics/actionbar/styling.html

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

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
  </style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
</style>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top