Android ConstraintLayout 添加背景颜色教程
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_height="match_parent" android:layout_width="match_parent" tools:context=".ui.home.HomeFragment" android:background="#FF0000">
<!-- 这里是布局的其他代码 -->
</androidx.constraintlayout.widget.ConstraintLayout>
要给ConstraintLayout添加一个背景颜色,可以在ConstraintLayout的属性中添加android:background属性。例如,如果要将背景颜色设置为红色,可以修改代码如下:
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".ui.home.HomeFragment"
android:background="#FF0000">
<!-- 这里是布局的其他代码 -->
</androidx.constraintlayout.widget.ConstraintLayout>
上述代码中,将android:background属性设置为'#FF0000',即红色的十六进制表示。您可以根据需要将其更改为其他颜色的十六进制表示。
原文地址: https://www.cveoy.top/t/topic/iUTP 著作权归作者所有。请勿转载和采集!