如何使用 Holo.Light 主题,并在蜂窝式设备上回退到“Light"? [英] How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?

查看:22
本文介绍了如何使用 Holo.Light 主题,并在蜂窝式设备上回退到“Light"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在支持它的设备上使用 Holo.Light 主题,并在其他设备上使用常规的 Light 主题.

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.

目前,引用 Holo.Light 在 3.0+ 上运行良好,但较旧的 API 只是恢复到默认的黑暗"主题.我可以通过样式继承实现我想要的吗?

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?

推荐答案

您必须创建一个自定义主题并将其保存在某些目录中才能最终将此主题设置为应用程序的默认主题

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

首先,在 values 添加一个 themes.xml,如下所示:

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> 

然后,在 res 目录中创建一个名为values-v11"(Android 3.0+)的目录,并放置一个像这样的 themes.xml

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>

最后在res目录下创建一个名为values-v14"(Android 4.0+)的目录,并创建一个themes.xml

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>

有了 DeviceDefault,您的应用程序在任何公司(HTC Samsung ...)的任何设备中都看起来很完美,这些设备为 Android 4 添加了创建的自定义主题

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

三星的界面 (TouchWiz) 不尊重此功能,应用在三星的设备上会非常难看.最好把 Holo 主题 :(

最后在你的 manifest.xml

Finally in your manifest.xml

 <application
        ...
        android:theme="@style/MyAppTheme">

这篇关于如何使用 Holo.Light 主题,并在蜂窝式设备上回退到“Light"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆