我想知道如何更改我的布局背景。
有多种方法可以实现这个目标,可以通过XML...
android:background
XML属性。它可以使用形式为"@drawable/imagefile"
的可绘制对象或颜色值"#FF000000"
。或使用以下函数以编程方式执行颜色更改:
setBackgroundResource
:将背景设置为给定资源。该资源应引用Drawable对象或0以删除背景。setBackgroundColor
:设置此视图的背景颜色。android:background="@drawable/image">
val mainLayout = findViewById<ConstraintLayout>(R.id.mainLayout)
mainLayout.setBackgroundColor(currentColor)