【发布时间】:2015-07-14 17:46:24
【问题描述】:
我看到新的 appCompat 控件可用here。并在 android 应用程序中实现它,但我没有找到任何自定义颜色的具体方法。
就像我们在样式中设置 accent color 一样,编辑文本会自动捕捉它。但是在 AppCompatButton 的情况下它不起作用。
有人找到这方面的东西吗?
【问题讨论】:
标签: android android-appcompat material-design
我看到新的 appCompat 控件可用here。并在 android 应用程序中实现它,但我没有找到任何自定义颜色的具体方法。
就像我们在样式中设置 accent color 一样,编辑文本会自动捕捉它。但是在 AppCompatButton 的情况下它不起作用。
有人找到这方面的东西吗?
【问题讨论】:
标签: android android-appcompat material-design
请看这里:Coloring Buttons in Android with Material Design and AppCompat
总而言之,您可以在按钮本身上使用tintBackground 属性,也可以使用colorControlNormal(或组合)。
此外,您可以只使用Button,只要您正确使用主题并从AppCompatActivity 继承,它就会转换为AppCompatButton。
链接网址中的示例
主题.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
【讨论】: