更改材料设计AppCompat动作条颜色颜色、动作、材料、AppCompat

2023-09-12 21:49:13 作者:离她心

我用来改变AppCompat状态栏的颜色与 actionBarStyle ,并创建一个背景,是我想要的颜色的样式。

I used to change AppCompat status bar color with actionBarStyle, and creating a style with a background which is the color I want.

现在,随着材料设计AppCompat,此方法不工作了。

Now, with Material Design AppCompat, this method doesn't work anymore.

您能帮我吗?谢谢你。

推荐答案

还有 colorPrimary 称为一个新的属性,你可以在你的主题定义。这会给你动作条或工具栏纯色。

There's a new attribute called colorPrimary which you can define in your Theme. This will give you ActionBar or Toolbar a solid color.

下面一个小例子:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/my_action_bar_color</item>
</style>

请注意:它必须是唯一的 colorPrimary ,不是安卓colorPrimary 在每一个价值观文件夹以外的值-V21 之一。

Please note: It has to be only colorPrimary, not android:colorPrimary, in every values-folder except the values-v21 one.

您可以阅读更多有关自定义调色板上的developer.android.com.

You can read more about customizing the Color Palette on developer.android.com.

 
精彩推荐
图片推荐