How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?

不想你离开。 提交于 2019-11-26 06:55:41

问题


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?


回答1:


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">



回答2:


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" />


来源:https://stackoverflow.com/questions/9681648/how-to-use-holo-light-theme-and-fall-back-to-light-on-pre-honeycomb-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!