77

I'd like to use the Holo.Light theme on devices that support it, and fall back to the regular Light theme on other devices.

At the moment, referencing Holo.Light works fine on 3.0+, but older APIs simply revert to the default 'dark' theme. Can I achieve what I want with with style inheritance?

Aracem
  • 7,227
  • 4
  • 35
  • 72
koi-feeding
  • 989
  • 1
  • 8
  • 9

2 Answers2

182

You have to create a custom theme and save it in some directories to finally set this theme as the default one for the app

First, in values add a themes.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Any customizations for your app running on pre-3.0 devices here -->
    </style>
</resources> 

Then, create a directory with the name "values-v11" (Android 3.0+ ) in the res directory and put a themes.xml like this

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
        <!-- Any customizations for your app running on 3.0+ devices here -->
    </style>
</resources>

Finally, create a directory with the name "values-v14" (Android 4.0+) in the res directory and create a themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
        <!-- Any customizations for your app running on 4.0+ devices here -->
    </style>
</resources>

With the DeviceDefault your app allways look perfect in any device of any company (HTC Samsung ... ) that add created custom themes for Android 4

EDIT: Samsung's interface (TouchWiz) dont respect this feature and the apps will be very ugly on Samsung's devices. Its better put Holo theme :(

Finally in your manifest.xml

 <application
        ...
        android:theme="@style/MyAppTheme">
Aracem
  • 7,227
  • 4
  • 35
  • 72
  • 1
    @Aracem, what do you mean by "very ugly"? Will it use the old light theme or worse? – l33t Mar 15 '13 at 23:44
  • 1
    I mean that if you set the theme DeviceDefault in some samsung devices the interface is like "not finished" or blank. Important, I dont know if all the samsung devices with Android 4.0+ has this bug! – Aracem Mar 19 '13 at 09:26
  • "All problems in computer science can be solved by another level of indirection" :-) – Luis Mendo Aug 15 '13 at 11:41
  • I confirm that Samsung's TouchWiz does not work well with Theme.DeviceDefault. On Galaxy Note my Dialog appears with black text and dark background (so almost unreadable). Furthermore, the app behind the dialog appears completely white. – Stan Feb 05 '14 at 14:40
  • I actually can't have it working. I don't know what I'm missin. I've followed these exact instructions but it didn't change anything. worth maybe mentionning that I'm using Phonegap with native dialogs boxes. It displays it in an ugly black dialog boxes that look 5 years old :/ – Miles M. Aug 07 '14 at 03:46
  • Can you tell me what API Version are you targeted? Yoou need to target > than 14 to see this. If this is not the solution perhaps there are something in phonegap or, probably, when you create natively the dialog, remember you have to put the Theme Style to the dialog. Perhaps this can help you http://stackoverflow.com/questions/18839895/change-dialog-theme-for-every-dialog – Aracem Aug 25 '14 at 12:20
0

You can also simply set the background to be white, and then go through and make all your other widgets black, like this:

<LinearLayout 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="#ffffff"
    android:orientation="vertical" >

<TextView
    android:id="@+id/tvText"
    android:text="@string/text"
    **android:textColor="#000000"
    android:textSize="12dp" />
Denizen
  • 335
  • 5
  • 17