0

I had previously set the colour of my window background to white and now I am trying to change the colour of just the action bar to green. This is my xml code:

<style name = "CustomAppTheme2" parent = "android:Widget.Holo.Light">

    <item name="android:windowBackground">@color/white</item>
    <item name="android:background">@color/green</item>
    <item name="android:icon">@android:color/transparent</item> 
</style>

The problem is that using android:background to change the colour of the action bar, it overflows and changes the colour of the whole screen to green. I want a clear-cut green action bar and a white window below it. Thanks in advance!

Will
  • 141
  • 1
  • 9
  • Check the accepted answer for this Question http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us – Pooja Mar 17 '15 at 07:05

2 Answers2

1
     <!-- Base application theme. -->
        <style name="AppTheme" parent="@style/CustomActionBarTheme">
            <!-- Customize your theme here. -->
        </style>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

            <!-- Support library compatibility -->

            <item name="android:actionBarStyle">@style/MyActionBar</item>

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

        <!-- ActionBar styles -->
        <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="android:background">@drawable/top_bar_blue</item>

            <!-- Support library compatibility -->
            <item name="background">@drawable/top_bar_blue</item>
            <item name="titleTextStyle">@style/myTheme.ActionBar.Text</item>
        </style>
    <!-- ActionBar Text -->
        <style name="myTheme.ActionBar.Text" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
            <item name="android:textColor">@android:color/white</item>
            <item name="android:textSize">20sp</item>
            <item name="android:textStyle">bold</item>
            <item name="android:fontFamily">sans-serif-bold</item>
        </style>
<!-- In Manifest -->
android:theme="@style/AppTheme"
Ammar ali
  • 1,503
  • 1
  • 15
  • 24
1

You could extend ActionBarActivity from one of your classes and do something like this:

ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(mTitle);

//Change the color of the actionbar by changing the value in the next line
actionBar.setBackgroundDrawable(new ColorDrawable(#FFFFFF));
unknown_seagull
  • 91
  • 1
  • 10