目前,我正在尝试为AppCompat v7:21上的操作栏设置自定义背景色。我已经尝试了许多可能性,直到现在我还无法弄清楚发生了什么。
这是我的res/values/styles.xml
:
<resources>
<color name="action_bar">#000</color>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/action_bar</item>
</style>
</resources>
我想通了!实际上,许多UI内容在API 21上发生了变化,在AppCompat v7上也发生了变化。您可以像这样设置操作栏颜色(以及其他设置):
<!-- extend one of the Theme.AppCompat themes -->
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- customize the color palette -->
<item name="colorPrimary">@color/material_blue_500</item>
<item name="colorPrimaryDark">@color/material_blue_700</item>
<item name="colorAccent">@color/material_green_A200</item>
</style>
其中的color*
键定义了相关视图的颜色,从而提供了在Lollipop上观察到的视觉一致性,即:不可能(根据我的尝试和错误检查),使用AppCompat v7时,请像我尝试的那样分别设置这些颜色。
观察 :我一直在使用他们试过了,小时前,在<style>
与parent="Widget.AppCompat.Light.ActionBar"
不工作。它们必须放在“根”<style>
元素内。正是这种错误使我写下了这个。
对不起,我的英语能力。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句