1

我一直在寻找一种在 android 5.0 中处理按钮背景颜色的正确方法,我能找到的唯一解决方案是在 values-21/styles.xml 中为 Button 定义样式:

<item name="android:colorButtonNormal">#2196f3</item>

这是为按钮着色的唯一方法,同时保留其设计和涟漪效果吗?如果是,这意味着我必须为每个具有不同颜色的按钮定义一个自定义主题,真的吗???

注意:我的问题与向后兼容性和 AppCompat 无关,这已经讨论了很多。

4

2 回答 2

0

您可以使用 tint 选项以这种方式更改颜色,而不是为每个按钮制作单独的主题,您只需将每个按钮着色为不同的颜色。见这里:材料设计绘图

于 2015-01-13T19:24:20.437 回答
0

colorButtonNormal是的,您必须为每种颜色定义一个单独的主题。您可以将主题设置为您Button的如下:

<style name="ColorButonButton" parent="Theme.AppCompat.Light">  
    <item name="colorButtonNormal">@color/newColor</item>
</style>

<Button  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Text"
    android:theme="@style/ColorButonButton"/>
于 2016-02-22T23:24:45.167 回答