为什么我不能改变按钮的颜色

时间:2021-07-20 00:39:34

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

我在 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 图像是:

before

添加颜色后的AVD图像是:

after

.

1 个答案:

答案 0 :(得分:0)

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

<Button
    ...
    app:backgroundTint="@color/next_button_color"/>
相关问题