Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the Background of all my activities in styles.xml

I am trying to customize my styles.xml file to display the same background for each one of my activities.

I tried this code in my styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.MyTheme" parent="android:Theme.NoTitleBar">
        <item name="android:background">@drawable/mybg</item>
    </style>
</resources>

this worked pretty well untill I put a TextView in my activity.. Every View I put in my layout get the same background, and that is really annoying

What is the best practice to set only the background of the activity?

like image 478
Waza_Be Avatar asked Mar 05 '12 10:03

Waza_Be


People also ask

Which XML is used to define custom themes and looks for the UI of application?

Themes can also apply styles to non-view elements, such as the status bar and window background. Styles and themes are declared in a style resource file in res/values/ , usually named styles. xml .

Where do styles go in XML?

Defining Styles This XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file.

What is styles XML?

Note: A style is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine style resources with other simple resources in the one XML file, under one <resources> element. The filename is arbitrary.


2 Answers

I think I have found my answer:

 <item name="android:windowBackground">

fits all my needs

like image 135
Waza_Be Avatar answered Sep 20 '22 14:09

Waza_Be


May be you can do it like this :

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="yourstylename">
    <item name="android:background">@drawable/mybg</item>
</style>

and set this style to all your activities root element in xml file.

like image 33
Rohit Avatar answered Sep 20 '22 14:09

Rohit