如何自定义 AppCompatButton 颜色

How to customize AppCompatButton color

我看到新的 appCompat 控件可用 here。并在 android 应用程序中实现了它,但我没有找到任何自定义其颜色的具体方法。

就像我们在样式中设置 强调色 一样,编辑文本会自动捕获它。但它在 AppCompatButton 的情况下不起作用。

有人找到与此相关的信息吗?

看这里:Coloring Buttons in Android with Material Design and AppCompat

总而言之,您可以在按钮本身上使用 tintBackground 属性,也可以使用 colorControlNormal(或组合)。

此外,您可以只使用 Button,只要您使用主题并正确继承 AppCompatActivity,它就会转换为 AppCompatButton

示例来自链接 URL

theme.xml:

<item name="colorButtonNormal">@color/button_color</item>

v21/theme.xml

<item name="android:colorButtonNormal">@color/button_color</item>

<Button
       android:id="@+id/add_remove_button"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:backgroundTint="@color/bg_remove_btn_default"
       android:textColor="@android:color/white"
       tools:text="Remove" />

像这样将 SupportLib 与 AppCompatButton 结合使用:

<android.support.v7.widget.AppCompatButton
       android:id="@+id/add_remove_button"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       app:backgroundTint="@color/bg_remove_btn_default"
       android:textColor="@android:color/white"
       tools:text="Remove" />

app 是一个 mxlns: xmlns:app="http://schemas.android.com/apk/res-auto"

所以 backgroundTint 也适用于 preLollipop