gpt4 book ai didi

android - Material 设计 : buttons won't take theme color?

转载 作者:行者123 更新时间:2023-11-29 17:45:48 25 4
gpt4 key购买 nike

在扩展了 material.light 主题后,设置颜色如下:

<resources>
<!-- inherit from the material theme -->
<style name="MiTemaMaterial" parent="android:Theme.Material.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#4DB6AC</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#009688</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#FFAB40</item>
</style> </resources>

我得到了一个类似 Material 设计的导航栏,但是像按钮这样的 View 不采用配色方案并且显示为默认值。我想知道这是否是标准行为,因为在此处的设计指南中 http://www.google.com/design/spec/components/buttons.html按钮似乎使用强调色。

我必须手动设置它们的样式吗?

最佳答案

是的,您需要自己为按钮设置主题。要提供一个采用原色的按钮,请在 v21 目录中使用可绘制的背景作为背景,例如:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:drawable="?attr/colorPrimary"/>
</ripple>

这将确保您的背景颜色为 ?attr/colorPrimary 并且使用默认的 ?attr/colorControlHighlight 具有默认的波纹动画(您也可以在主题中设置如果你愿意的话)。

注意:您必须为低于 v21 的版本创建自定义选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/primaryPressed" android:state_pressed="true"/>
<item android:drawable="@color/primaryFocused" android:state_focused="true"/>
<item android:drawable="@color/primary"/>
</selector>

假设您有一些您想要的默认、按下和聚焦状态的颜色。就个人而言,我在被选中的过程中截取了一个涟漪的屏幕截图,并将主要/专注状态从中拉出来。

关于android - Material 设计 : buttons won't take theme color?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26836058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com