API 21下的主要暗色机器人

Nic*_*ick 3 android android-5.0-lollipop

我想为状态栏着色,以便在Android 5.0中更好看.我想设置三种颜色的primarydark,light和accent.

但我的最低API是15.有没有机会在API lvl 21下使用它?或者我必须用min创建一个单独的应用程序.sdk 21?

编辑:现在我得到我需要的一切,但statisbar颜色不会改变.

这是我的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>
Run Code Online (Sandbox Code Playgroud)

这是普通的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>
Run Code Online (Sandbox Code Playgroud)

任何想法为什么这不起作用?

ipa*_*avl 8

您可以针对不同的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>
Run Code Online (Sandbox Code Playgroud)

res/values-v21/colors.xml:

<!-- Colours for API 21+ -->
<color name="primaryDark">#000008</color>
<color name="light">#080008</color>
<color name="accent">#0000FF</color>
Run Code Online (Sandbox Code Playgroud)