Android按钮背景颜色不起作用

时间:2021-02-20 10:09:21

标签: android xml button background

我刚开始学习 android 并遇到了这个问题。看了几个教程,但找不到解决方案。 所以基本上我想在网格布局中添加一个按钮。我希望按钮颜色为白色。所以我在按钮属性中添加了 android:background="#ffffff" 。但它仍然显示默认颜色,即蓝色。 请帮忙更改按钮颜色!!

这里是xml代码。

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#007b7e"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <androidx.gridlayout.widget.GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="30sp"
        android:layout_row="3"
        android:layout_column="3">


        <Button
            android:id="@+id/button10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:textSize="18sp"
            android:layout_margin="5sp"
            android:gravity="fill"
            android:text="Button"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"/>



    </androidx.gridlayout.widget.GridLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

尝试使用 AppCompactButton 而不是

<Button/>

使用

<androidx.appcompat.widget.AppCompatButton />

这样做就行了