1

我正在尝试找出为新旧 Android 版本选择最佳主题的最佳方法,例如通过阅读此Trying to use holo theme in Android not working where they defined Holo in values-11 and Black in values

黑色的

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.MyTheme" parent="@android:style/Theme.Black" />
</resources>

全息

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.MyTheme" parent="@android:style/Theme.Holo" />
</resources>

问题 1)无论我使用什么 minSdkVersion 设置,它都会起作用吗?我猜 Android for never 版本将假定values-11values .fallback 当没有特定文件夹匹配时更好匹配

问题 2)假设以上(我认为是这种情况),我如何/在哪里最好地定义我的MyTheme扩展。假设我有:

<style name="MyTheme2" parent="MyTheme">
  <item name="android:windowTitleSize">44dip</item>
  <item name="android:windowTitleBackgroundStyle">@style/MyWindowTitleBackground</item>            
</style>               
<style name="MyWindowTitleBackground">
  <item name="android:background">@android:color/transparent</item>
  <item name="android:padding">0px</item>
</style>

我是否必须在两个 styles.xml文件中复制它?或者我可以以某种方式将其放在共享文件夹中吗?据我了解,我认为这不可能吗?

我是 Android 新手,所以我只是想弄清楚最好的办法是什么:)

4

1 回答 1

1

应在values/styles中创建独立定制。遵循此模板:(ANDROID 默认)

价值观/风格

<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:style/Theme.Black">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

        -->
    </style>

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

</resources>

values-v11/styles

<resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- API 11 theme customizations can go here. -->
    </style>

</resources>
于 2013-02-04T14:23:08.830 回答