问题描述
我要的颜色的状态栏,在安卓5.0更好看。我想设置的三色primarydark,光线和重点。
i want to color the Statusbar, for a better look in Android 5.0. I want to set the three color primarydark,light and accent.
不过,我最小的API为15。是否有任何机会,正好利用这个刚下API拉特21?或者,我必须创建分钟一个单独的应用程序。 SDK 21?
But my minimum API is 15. Is there any chance just to use this just under API lvl 21? Or do I have to create a seperate app with min. sdk 21?
编辑:现在我得到我需要的一切,但statisbar颜色不会改变。
Now i get everything i needed but the statisbar color won't change.
这是我的价值观-V21 / styles.xml
This is my 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
And this the normal 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>
任何想法,为什么这是行不通的?
Any Ideas why this won't work?
推荐答案
您可以有不同的风格不同的API级别。
You can have different styles for different API levels.
有关API&LT; 21,你可以使用普通的 RES /价值/ styles.xml
,然后为API 21+,你会 RES /值-V21 / styles.xml
。
For API < 21, you would use a normal res/values/styles.xml
, and then for API 21+, you would have res/values-v21/styles.xml
.
如果设备运行的是API 21或更高,那么它会使用在 -v21
文件夹中的文件。如果你只是想设置&LT;色&GT;
的值,那么就命名密钥相同,并且与 colors.xml 。
If the device is running API 21 or higher, then it will use the file in the
-v21
folder. If you just want to set <color>
values, then just name the keys the same and do the same with colors.xml
.
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
例如:
RES /价值/ colors.xml
:
<!-- Colours for API <21 -->
<color name="primaryDark">#800000</color>
<color name="light">#800080</color>
<color name="accent">#FF0000</color>
RES /值-V21 / colors.xml
:
<!-- Colours for API 21+ -->
<color name="primaryDark">#000008</color>
<color name="light">#080008</color>
<color name="accent">#0000FF</color>
这篇关于根据API小学21深色的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!