Android 材料设计:按钮赢得';你不选主题色吗?
扩展material.light主题并设置如下颜色后:Android 材料设计:按钮赢得';你不选主题色吗?,android,material-design,Android,Material Design,扩展material.light主题并设置如下颜色后: <resources> <!-- inherit from the material theme --> <style name="MiTemaMaterial" parent="android:Theme.Material.Light"> <!-- Main theme colors --> <!-- your app brandin
<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>
#4DB6AC
#009688
#FFAB40
我得到了一个类似导航栏的材质设计,但像按钮这样的视图不采用颜色方案,显示为默认值。我想知道这是否是标准行为,因为在这里的设计指南中,Button似乎使用了强调色
我必须手动设置它们的样式吗?是的,您需要自己设置按钮的主题。要提供采用原色的按钮,请在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>
假设您有一些默认、按下和聚焦状态所需的颜色。就我个人而言,我在被选中的中途拍下了一张涟漪的截图,并将主要/焦点状态从中拉了出来。我明白了,谢谢!我想我还需要手动设置所有其他视图的主题,比如单选按钮之类的,对吗?大多数组件都会自动使用部分主题颜色。可能有助于进行试验
<?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>