Android studio 重置kotlin中按钮的颜色
我是安卓工作室的新手。我正在做Tic-Tac-toe,当我点击按钮时,它会改变它的背景颜色和文本Android studio 重置kotlin中按钮的颜色,android-studio,kotlin,tic-tac-toe,Android Studio,Kotlin,Tic Tac Toe,我是安卓工作室的新手。我正在做Tic-Tac-toe,当我点击按钮时,它会改变它的背景颜色和文本 clickedView.text = "x" clickedView.setBackgroundColor(Color.CYAN) 这是.XML文件中的按钮: <Button android:id="@+id/button1" android:layout_height="45pt"
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));
或从默认颜色中选择
yourView.setBackgroundColor(ContextCompat.getColor(this, R.color.green));
yourView.setBackgroundColor(getResources().getColor(R.color.black));
按钮没有其原始颜色的记忆。您只需使用相同的
setBackgroundColor
函数手动更改为所需的颜色。谢谢,但我只是使用“R.color”在styles的xml文件中查找默认颜色。谢谢!这很有帮助。