【问题标题】:Android set default device themeAndroid设置默认设备主题
【发布时间】:2013-04-10 21:21:55
【问题描述】:

我有一个可以在 2.2 到 4.x 设备上运行的应用。

当我在 4.x 上运行这个应用程序时,它看起来很酷,全息风格。但是当我在旧设备上运行它时,它似乎非常“轻巧”。

有一个截图,你可以比较:

这是我的清单:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

还有我的风格:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">

</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

很明显 holo 在 2.3 中不存在,但它应该呈现它的默认设备主题,对吧?

所以输入是正确的,但是 TextView 看起来太灰了。

有什么想法吗?

【问题讨论】:

  • 在你的截图中看起来不是很灰...顺便说一句,你可能会觉得这很有趣:github.com/Prototik/HoloEverywhere
  • 不是提示,标题从输入开始,左边是黑色,右边是灰色..
  • "很明显 holo 在 2.3 中不存在,但是它应该呈现它的默认设备主题,对吧?" -- 理想情况下,您使用版本化样式资源(例如,res/values/res/values-v11/),因此您可以具体地控制在预 Holo 设备上使用的基本主题。

标签: android android-layout


【解决方案1】:

正如有人建议的那样,我终于创建了一个新文件夹: res/values-v11/ 在这个文件夹中,我放了一个名为styles.xml 的文件,内容如下:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">

</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

并且将为 api 低于 11 的 android 调用的文件夹 res/values/ 包含一个 styles.xml 并且我已经更改了父模板,如下所示:

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="MyTheme" parent="@android:style/Theme.Light">

</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

结果是这样的:

  • API 高于 11 的设备 -> holo 主题
  • 其余部分:Theme.Light(“普通主题”)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 2016-12-12
    相关资源
    最近更新 更多