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?
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 .
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.
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.
I think I have found my answer:
<item name="android:windowBackground">
fits all my needs
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With