Search code examples
androidcolorsbackgroundandroid-actionbarnavigation-drawer

How to set custom ActionBar color / style?


I am using Android Navigation bar in my project, I want to change the top color in action bar to something red, How can i do that? I have something like this,

top black

and i want something like this,

top red

how can i achieve that?


Solution

  • You can define the color of the ActionBar (and other stuff) by creating a custom Style:

    Simply edit the res/values/styles.xml file of your Android project.

    For example like this:

    <resources>
        <style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
            <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
        </style>
    
        <style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
            <item name="android:background">ANY_HEX_COLOR_CODE</item>
        </style>
    </resources>
    

    Then set "MyCustomTheme" as the Theme of your Activity that contains the ActionBar.

    You can also set a color for the ActionBar like this:

    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED)); // set your desired color
    

    Taken from here: How do I change the background color of the ActionBar of an ActionBarActivity using XML?