简体   繁体   English

如何在android布局中更改背景

[英]how to change background in android layout

我想知道如何更改布局背景。

There are multiple ways to accomplish this, it can be done via XML...有多种方法可以实现这一点,它可以通过 XML 来完成...

  • android:background XML attritube. android:background XML 属性。 This can use a drawable in the form of "@drawable/imagefile" or a color value "#FF000000" .这可以使用"@drawable/imagefile"形式的"@drawable/imagefile"或颜色值"#FF000000"

or perform the color change programmatically with the following functions:或使用以下功能以编程方式执行颜色更改:

in layout tag in your xml file write在 xml 文件中的布局标记中写入

android:background="@drawable/image">

and put image.jpg(gif,bmp,png) on drawable folder并将 image.jpg(gif,bmp,png) 放在 drawable 文件夹中

This might help: You can set layout color as well as an image to it.这可能会有所帮助:您可以为其设置布局颜色和图像。

change background color of the layout in Android 在 Android 中更改布局的背景颜色

Configure background programmatically in Kotlin language:在 Kotlin 语言中以编程方式配置后台:

    val mainLayout = findViewById<ConstraintLayout>(R.id.mainLayout)
    mainLayout.setBackgroundColor(currentColor)

You can change the ConstraintLayout to whatever Layout you want.您可以将 ConstraintLayout 更改为您想要的任何布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM