Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - how to set background color of all screens?

What is the best practice to maintain styles of fonts and colors. I made a colors.xml file which I have used to change colors on seperate elements like buttons, but I am not sure how Android wants developers to organize their styles.

For example, I would like all screens to have the same background color. How do I do that? Is it something I need to specify for each Activity layout xml? Or elsewhere? How do I accomplish it?

like image 739
GeekedOut Avatar asked Apr 14 '12 19:04

GeekedOut


People also ask

How do I make my background white on Android?

Use either the Auto or manual mode to remove the background. Tap on the next icon at the top. Tap on Color tab at the bottom. Using sliders, select the color white.


1 Answers

A quick and easy way to make sure every activity has the same background color, is to create a theme for your activities to use. That theme would specify the android:windowBackground.

First define the color in values/colors.xml

<resources>     <color name="background">#FF0000 </color> </resources> 

Create a themes.xml file in res/values that references that color:

<resources>  <style name="MyTheme" parent="@android:style/Theme.Light">    <item name="android:windowBackground">@color/background</item>  </style> </resources> 

... and then in your AndroidManifest.xml specify this as the theme for your activities to use.

 <activity         android:name=".MyActivity"         android:theme="@style/MyTheme" /> 
like image 180
NPike Avatar answered Oct 17 '22 12:10

NPike