android - API 21 下的原色深色 android

标签 android android-5.0-lollipop

我想给状态栏上色,以便在 Android 5.0 中看起来更漂亮。我想设置三种颜色 primarydark,light 和 accent。

但我的最低 API 是 15。是否有机会在 API 等级 21 下使用它?或者我是否必须使用 min 创建一个单独的应用程序。 SDK 21?

编辑: 现在我得到了我需要的一切,但统计栏颜色不会改变。

这是我的 values-v21/styles.xml

    <?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="android:Theme.Material.Light">
            <!-- API 21 theme customizations can go here. -->
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
        </style>
</resources>

这是普通的 style.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.Light">
        <!--
            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>

    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
        parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/blue</item>
    </style>
</resources>

知道为什么这行不通吗?

最佳答案

您可以针对不同的 API 级别使用不同的样式。

对于 API < 21,您可以使用普通的 res/values/styles.xml ,然后对于 API 21+,您将拥有 res/values-v21/styles.xml .

如果设备运行的是 API 21 或更高版本,那么它将使用 -v21 中的文件文件夹。如果你只想设置 <color>值,然后只需将键命名为相同的名称并对 colors.xml 执行相同的操作.

http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

例子:

res/values/colors.xml :

<!-- Colours for API <21 -->
<color name="primaryDark">#800000</color>
<color name="light">#800080</color>
<color name="accent">#FF0000</color>

res/values-v21/colors.xml :

<!-- Colours for API 21+ -->
<color name="primaryDark">#000008</color>
<color name="light">#080008</color>
<color name="accent">#0000FF</color>

关于android - API 21 下的原色深色 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26444391/

相关文章:

android - 如何立即运行workmanager

bluetooth - 用于 BLE 广告的 Android 5 静态蓝牙 MAC 地址

java - 如何理解 "(Editable) super.getText();"

android - 带有 ImageView 和 TextView 的 SimpleCursorAdapter

java - getCameraIdList() 函数返回一个空数组

java - 安卓 5.0 IllegalArgumentException : Service Intent must be explicit: on com. google.android.location.internal.GoogleLocationManagerService.START

android - MediaPlayer.prepare() 在 Android L 上抛出 IllegalStateException

android - Action 栏 android L

使用 AES 的 Android Lollipop 解密无法正常工作

android - 针对多个模型类执行 Realm 查询