繁体   English   中英

如何使用Holo.Light主题,并在蜂窝前设备上回归'Light'?

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

我想在支持它的设备上使用Holo.Light主题,然后回到其他设备上的常规Light主题。

目前,引用Holo.Light在3.0+上工作正常,但较旧的API只是恢复到默认的“黑暗”主题。 我可以通过样式继承来实现我想要的吗?

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

首先,在值中添加一个这样的themes.xml:

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

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

<?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三星...)中看起来完美,为Android 4添加创建的自定义主题

编辑:三星的界面(TouchWiz)不尊重这个功能,应用程序将在三星的设备上非常难看。 它更好的把Holo主题:(

最后在manifest.xml中

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

您也可以简单地将背景设置为白色,然后将所有其他小部件设置为黑色,如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM