I am trying to get all of my activities to have a custom theme style that should look like this:
This theme works on many devices, including the Nexus 7, the Samsung Galaxy S4, and the Samsung Droid Charge (running Gingerbread). However, on other devices, such as HP Slate 7 and Motorola Droid RAZR, it ends up looking like this:
I have the following in my AndroidManifest.xml
's application
tag:
android:theme="@style/AppTheme"
The theme is as follows in res/values/styles.xml
:
<style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar">
</style>
<style name="AppTheme" parent="@style/AppBaseTheme">
<item name="android:windowBackground">@color/background</item>
</style>
I have also added a styles.xml
under res/values-v11
. Here is the applicable style from there:
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
</style>
Finally, this appears in styles.xml
under res/values-v14
:
<style name="AppBaseTheme" parent="@android:style/Theme.DeviceDefault.Light">
</style>
I have tried to define the theme for each activity and to manually use the setTheme()
function in onCreate()
, but nothing has worked. I have also tried to manually set a background in every Activity
, and this did not work either. What can I do to fix my problem?
EDIT: What's interesting is setting android:background
in the styles makes it work, but then elements that should not have backgrounds receive that background color as well.
I found that the latest version of Android Studio expect that the parent for the style needs to be Theme.AppCompat. Also, it is good style to create a colors.xml file in the values directory (with named color elements between the resource tags). Put your RGB values as values to the named color elements. Reference them in your styles with @color/.
The key to solving the problem was changing
android:windowBackground
in the theme to the following:Notice that I am no longer using
@color
, but simply a@drawable
, the xml for which is below:It seems that some devices do not support accepting a color for this element.