在科特林中重置按钮的颜色

reseting color of button in kotlin

我是 android 工作室的新人。我正在制作井字游戏,当我点击按钮时,它改变了它的背景颜色和文本。

clickedView.text = "x"
clickedView.setBackgroundColor(Color.CYAN)

这是 .XML 文件中的按钮:

<Button
        android:id="@+id/button1"
        android:layout_height="45pt"
        android:layout_width="45pt"
        android:background="@color/colorPrimary"
        android:layout_margin="2dp"
        android:textSize="45sp"
        android:textColor="@color/white"
        />

所以,现在我正在制作重置按钮,但我不知道如何在默认情况下更改按钮的背景颜色。你能帮我吗?

您可以从十六进制代码

中获取颜色
yourView.setBackgroundColor(Color.parseColor("#000000"));

或从资源

获取
yourView.setBackgroundColor(ContextCompat.getColor(this, R.color.green)); 

或从默认颜色

yourView.setBackgroundColor(getResources().getColor(R.color.black));