【问题标题】:How to customize AppCompatButton color如何自定义 AppCompatButton 颜色
【发布时间】:2015-07-14 17:46:24
【问题描述】:

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

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

有人找到这方面的东西吗?

【问题讨论】:

    标签: android android-appcompat material-design


    【解决方案1】:

    请看这里: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" />
    

    【讨论】:

    • 一个大问题的简单答案。谢谢!
    【解决方案2】:

    像这样将 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

    【讨论】:

      猜你喜欢
      • 2016-03-05
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多