我如何更改kotlin中按钮的背景颜色

How do i change the backgroud color of a button in kotlin

我是 kotlin 编程的新手,我无法解决我在 android studio 中面临的问题。我学习了 youtube 上的一门课程,视频教你如何构建一个实际的应用程序。我想更改我制作的按钮的背景颜色,但无论我做什么,按钮都保持紫色。

我尝试了这两种方法:

android:background="@android:color/white"
android:background="#FFFFFF"

你们能帮帮我吗,我真的很感激

整个代码是:(请不要介意我为颜色选择的名称,我是罗马尼亚语)

<LinearLayout 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:id="@+id/padding"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity"
>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:background="@android:color/white"
    android:backgroundTint="@color/white"
    android:text="Selecteaza data"
    android:textColor="@color/culoarePrimara"
    android:textSize="20sp"
    android:textStyle="bold"
    />
</LinearLayout>

这是颜色:

对于按钮背景颜色,使用自定义样式或android:backgroundTint="@color/white"(或您喜欢的颜色)

而不是android:background="@color/backgroundColor"

使用:android:backgroundTint="@color/backgroundColor"

您可以使用:

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

可能您使用的是 Theme.MaterialComponents.* 主题,Button(已被 MaterialButton 替换)的默认背景颜色是 colorPrimary 中定义的您的应用主题。