【问题标题】:why i can'nt be able to change the color of buttons为什么我不能改变按钮的颜色
【发布时间】:2021-09-27 13:57:19
【问题描述】:

我在 color.xml 中添加了新颜色并将 main.xml 文件中的这些颜色设置为按钮,但我的按钮颜色仍然是蓝色/默认我不知道为什么会发生这种情况。 如果有人知道是什么问题,请帮我解决这个问题。

color.xml文件代码为:

<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="share_button_color">#271B1B</color>
<color name="next_button_color">#21EA13</color>

main.xml 文件代码为:

<Button
    android:id="@+id/sharememe"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="20dp"
    android:text="share"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@id/guideline2"
    app:layout_constraintTop_toBottomOf="@id/guideline3"
    android:onClick="Sharememe"
    android:background="@color/share_button_color" />

<Button
    android:id="@+id/nextmeme"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="20dp"
    android:text="next"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toRightOf="@id/guideline2"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/guideline3"
    tools:layout_editor_absoluteX="269dp"
    tools:layout_editor_absoluteY="540dp"
    android:onClick="Nextmeme"
    android:background="@color/next_button_color"/>


 

    

添加颜色前的 AVD 图像是:

添加颜色后的 AVD 图像是:

.

【问题讨论】:

    标签: android-studio android-button chrome-app-developer-tool


    【解决方案1】:

    材质按钮使用backgrountTint 属性为其背景着色而不是background 属性,因此将background 属性替换为:

    <Button
        ...
        app:backgroundTint="@color/next_button_color"/>
    

    【讨论】:

    • 好的,非常感谢亲爱的。愿上帝保佑你。你能告诉我黑白材料按钮和简单按钮的区别吗?
    • 不客气,如果答案有助于将其标记为已接受的答案以帮助他人。 Material 按钮是按Google Material design guidelines 设计的普通按钮,包括阴影、插图、圆角半径、触摸手势等,在Android support library 的帮助下绘制在所有API 版本上。
    • @MUHAMMADHASEEB 关于区别可以查看stackoverflow.com/questions/57925853/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 2010-11-22
    • 1970-01-01
    • 2020-10-13
    • 2011-11-23
    • 2021-02-15
    • 2018-04-19
    相关资源
    最近更新 更多