2

In continues to this question, I'd like to change the colors of both the actionbar (the upper pane)to one color and the rest of the screen to a different color.
How can I do it?
when I tried this -

<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>        
        <item name="android:background">#ffffd982</item> 
</style>

it seems like the 'android:background' definition override also the actionbarstyle definition

Community
  • 1
  • 1
GyRo
  • 2,586
  • 5
  • 30
  • 38

2 Answers2

2

Indeed, the background attribute is known to supersede the actionBarStyle attribute. However, changing the color of the entire Activity needs to be done through the Activity's XML layout, using the android:background attribute of the parent ViewGroup. The ActionBar styles won't help you there.

In your Activity's root ViewGroup, set the background attribute as:

<LinearLayout
    android:id="@+id/outermost_viewgroup"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background = "#00FF00"
    ....
    ....

EDIT:

I just realized that there is a way for this:

<item name="android:windowBackground">@color/background</item>

Add the above tag to to your ActionBar style definition, and the background in the colors.xml file:

<resources>
    <color name="background">#00FF00 </color>
</resources>

There, done!

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • Hi, I want to set the background for ALL the activities of my application, not for a single activity – GyRo Feb 26 '15 at 11:06
  • I completely forgot that there's a way to do what you want ... please see edited answer! – Yash Sampat Feb 26 '15 at 11:11
  • The 'android:windowBackground' tag didn't effect the 'android:windowBackground' style but when I put your suggested item in my main Theme definition it worked. But you were close enough and I simpathies you, so I accept this answer – GyRo Mar 01 '15 at 10:01
0

To change Actionbar style In your style.xml file define style like bellow

<style name="AppBaseTheme" parent="android:Theme.Light">

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.ActionBar">
    <item name="android:background"><YourColor></item>
    <item name="android:titleTextStyle"><Your String Color></item>
</style>

In your menifest.xml file used your style inside application tag like bellow

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

And for set background color of your activity just set android:background attribute in your each activity like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff2323"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:layout_marginTop="121dp"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

I think this is work for you...!

Bhadresh
  • 115
  • 2
  • 3
  • 13