Jetpack Compose 控件参数速查手册

本文是 Compose 系列配套参考手册,包含每个控件的完整参数、示例和注意事项。配合 Compose 从 0 到 1 食用更佳。


前言:Compose 控件体系概览

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Composable 函数(所有 UI 都是函数)
├── Text(文本)
├── Button(按钮)
├── TextField / OutlinedTextField(输入框)
├── Image(图片)
├── Checkbox(复选框)
├── Switch(开关)
├── RadioButton(单选按钮)
├── Slider(滑动条)
├── Column(纵向布局)
├── Row(横向布局)
├── Box(层叠布局)
├── LazyColumn / LazyRow(列表控件)
├── Scaffold(页面骨架)
│ ├── TopAppBar(顶部栏)
│ ├── BottomAppBar / NavigationBar(底部栏)
│ └── FloatingActionButton(浮动按钮)
└── Modifier(外观修饰,适用于所有控件)

Modifier 是所有控件共用的外观修饰系统,详见第十四章。

Text —— 文本

作用

显示文字。Compose 中最基础的控件,替代传统 TextView

核心属性

参数类型说明
textString显示的文本内容
modifierModifier外观修饰(大小、边距、背景等)
colorColor文字颜色,如 Color.BlueColor(0xFF333333)
fontSizeTextUnit字号,如 16.sp
fontStyleFontStyleFontStyle.Normal / FontStyle.Italic
fontWeightFontWeight字重:Thin / Light / Normal / Medium / Bold / Black
fontFamilyFontFamily字体,如 FontFamily.Default / FontFamily.Monospace
letterSpacingTextUnit字母间距,如 1.sp
textDecorationTextDecorationNone / Underline / LineThrough
textAlignTextAlign对齐方式:Left / Center / Right / Justify / Start / End
lineHeightTextUnit行高,如 24.sp
maxLinesInt最大行数,超出后按 overflow 处理
overflowTextOverflow超出处理:Ellipsis(省略号)/ Clip(裁剪)/ Visible(可见)
softWrapBoolean是否自动换行,默认 true
styleTextStyle统一样式对象,可一次性设置多个文字属性
onTextLayout(TextLayoutResult) -> Unit文字布局完成回调

示例

1
2
3
4
5
6
7
8
Text(
text = "Hello Compose",
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Blue,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)

适用场景

  • 页面标题、正文、标签、提示信息等一切需要显示文字的地方

⚠️ 注意

  • fontSize 必须带单位 .sp,否则编译报错
  • overflow = TextOverflow.Ellipsis 只在 maxLines 设置后生效
  • 需要渐变文字或复杂样式时,使用 buildAnnotatedString + ClickableText

Button —— 按钮

作用

用户点击触发操作。Compose 中最核心的交互控件,Material 3 风格。

核心属性

参数类型说明
onClick() -> Unit点击回调
modifierModifier外观修饰
enabledBoolean是否可点击,false 时变灰,默认 true
colorsButtonColors颜色配置,由 ButtonDefaults.buttonColors() 创建
elevationButtonElevation阴影高度,由 ButtonDefaults.buttonElevation() 创建
shapeShape按钮形状,如 RoundedCornerShape(8.dp)
borderBorderStroke?边框,如 BorderStroke(1.dp, Color.Gray)
contentPaddingPaddingValues内容内边距,默认 ButtonDefaults.ContentPadding
interactionSourceMutableInteractionSource交互状态源(高级用法)
content@Composable RowScope.() -> Unit按钮内部内容(通常是 Text + 图标组合)

示例

1
2
3
4
5
6
7
8
Button(
onClick = { },
colors = ButtonDefaults.buttonColors(
containerColor = Color.Blue
)
) {
Text("点击我")
}

文字按钮(TextButton)

1
2
3
TextButton(onClick = { }) {
Text("取消")
}

描边按钮(OutlinedButton)

1
2
3
OutlinedButton(onClick = { }) {
Text("了解更多")
}

适用场景

  • 提交表单、页面跳转、确认/取消操作等点击交互

⚠️ 注意

  • content 中使用 RowScope,可以横向排列多个元素(如图标 + 文字)
  • Material 3 默认没有阴影,区别于传统 MaterialButton
  • ButtonDefaults.buttonColors() 可配置:containerColorcontentColordisabledContainerColordisabledContentColor

TextField —— 输入框

作用

用户输入文字。Material 3 提供两种样式:TextField(填充)和 OutlinedTextField(描边)。

核心属性

参数类型说明
valueString当前输入内容,必填
onValueChange(String) -> Unit输入变化回调,必填
modifierModifier外观修饰
enabledBoolean是否可用,默认 true
readOnlyBoolean是否只读,默认 false
label@Composable (() -> Unit)?浮动标签,如 { Text("用户名") }
placeholder@Composable (() -> Unit)?占位文字,如 { Text("请输入") }
leadingIcon@Composable (() -> Unit)?左侧图标
trailingIcon@Composable (() -> Unit)?右侧图标(常用于清除按钮)
isErrorBoolean是否显示错误状态,默认 false
supportingText@Composable (() -> Unit)?底部辅助文字(错误提示 / 字符计数)
singleLineBoolean是否单行,默认 false
maxLinesInt最大行数
keyboardOptionsKeyboardOptions键盘类型:KeyboardOptions(keyboardType = KeyboardType.Password)
keyboardActionsKeyboardActions键盘动作:KeyboardActions(onDone = { ... })
colorsTextFieldColors颜色配置
textStyleTextStyle文字样式
visualTransformationVisualTransformation视觉变换,如 PasswordVisualTransformation()
shapeShape形状

KeyboardType 常用值

场景
KeyboardType.Text普通文本
KeyboardType.Password密码
KeyboardType.Number数字
KeyboardType.Decimal带小数点数字
KeyboardType.Phone电话号码
KeyboardType.Email邮箱地址
KeyboardType.Uri网址

示例

1
2
3
4
5
6
7
8
9
var text by remember { mutableStateOf("") }

TextField(
value = text,
onValueChange = { text = it },
label = { Text("用户名") },
placeholder = { Text("请输入") },
singleLine = true
)

适用场景

  • 登录/注册表单、搜索框、评论输入、聊天输入、任何需要用户输入的地方

⚠️ 注意

  • valueonValueChange必填参数,缺一不可
  • 必须配合 remember { mutableStateOf("") } 使用,否则无法输入
  • 密码框用 visualTransformation = PasswordVisualTransformation()
  • OutlinedTextField 参数与 TextField 几乎相同,只是外观为描边样式

Image —— 图片

作用

显示图片,支持本地资源、网络图片、位图等。

核心属性

参数类型说明
painterPainter图片资源,painterResource(R.drawable.xxx)
contentDescriptionString?无障碍描述,必填(纯装饰可传 null
modifierModifier外观修饰
alignmentAlignment图片在控件内的对齐方式,默认 Alignment.Center
contentScaleContentScale缩放方式(见下表)
alphaFloat透明度,0f ~ 1f,默认 1f
colorFilterColorFilter?颜色滤镜,如 ColorFilter.tint(Color.Red)

ContentScale 常用值

效果
Crop裁剪填满,保持比例(类似 centerCrop)
Fit等比缩放,完全显示(类似 fitCenter)
FillBounds拉伸填满,不保持比例(类似 fitXY)
FillWidth宽度填满,高度按比例
FillHeight高度填满,宽度按比例
None原始尺寸,不缩放

示例

1
2
3
4
5
6
Image(
painter = painterResource(id = R.drawable.ic_launcher),
contentDescription = "应用图标",
modifier = Modifier.size(100.dp),
contentScale = ContentScale.Crop
)

适用场景

  • 头像、商品图、Banner、图标、背景图等

⚠️ 注意

  • contentDescription 应始终提供有意义的描述,纯装饰性图片传 null
  • 加载网络图片需要引入图片加载库(Coil / Glide),painterResource 只能加载本地资源
  • 圆形头像裁剪用 Modifier.clip(CircleShape)

Checkbox —— 复选框

作用

多选开关,用户勾选/取消勾选。

核心属性

参数类型说明
checkedBoolean是否勾选
onCheckedChange((Boolean) -> Unit)?勾选状态变化回调
modifierModifier外观修饰
enabledBoolean是否可用,默认 true
colorsCheckboxColors颜色配置,CheckboxDefaults.colors()

示例

1
2
3
4
5
6
var checked by remember { mutableStateOf(false) }

Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(checked = checked, onCheckedChange = { checked = it })
Text("我同意用户协议")
}

三态复选框(TriStateCheckbox)

1
2
3
4
5
6
7
8
9
var state by remember { mutableStateOf(ToggleableState.Off) }

TriStateCheckbox(state = state, onClick = {
state = when (state) {
ToggleableState.Off -> ToggleableState.Indeterminate
ToggleableState.Indeterminate -> ToggleableState.On
ToggleableState.On -> ToggleableState.Off
}
})

适用场景

  • 协议勾选、多选列表、设置项开关

⚠️ 注意

  • onCheckedChange 是可空的,设为 null 可禁用交互(但不改变外观)
  • 通常搭配 Row + Text 组成完整的选项行
  • TriStateCheckbox 支持三个状态:未选 / 半选 / 全选,适合全选场景

Switch —— 开关

作用

开关控件,用于切换两种互斥状态(如开关某项功能)。

核心属性

参数类型说明
checkedBoolean是否开启
onCheckedChange((Boolean) -> Unit)?状态变化回调
modifierModifier外观修饰
enabledBoolean是否可用,默认 true
colorsSwitchColors颜色配置,SwitchDefaults.colors()
thumbContent@Composable (() -> Unit)?滑块内部内容(可放图标)

示例

1
2
3
var isOn by remember { mutableStateOf(true) }

Switch(checked = isOn, onCheckedChange = { isOn = it })

带图标的开关

1
2
3
4
5
6
7
Switch(
checked = isWiFi,
onCheckedChange = { isWiFi = it },
thumbContent = if (isWiFi) {
{ Icon(Icons.Default.Wifi, contentDescription = null, modifier = Modifier.size(16.dp)) }
} else null
)

适用场景

  • 设置页功能开关(WiFi、蓝牙、通知等)

⚠️ 注意

  • SwitchCheckbox 语义不同:Switch 表示即时生效的状态切换,Checkbox 表示需要提交的选项
  • colors 可配置:checkedThumbColorcheckedTrackColoruncheckedThumbColoruncheckedTrackColor

RadioButton —— 单选按钮

作用

多选一,用户从一组选项中选择一个。

核心属性

参数类型说明
selectedBoolean是否被选中
onClick(() -> Unit)?点击回调
modifierModifier外观修饰
enabledBoolean是否可用,默认 true
colorsRadioButtonColors颜色配置,RadioButtonDefaults.colors()

示例

1
2
3
4
5
6
7
8
9
10
11
12
val options = listOf("男", "女", "保密")
var selected by remember { mutableStateOf(options[0]) }

options.forEach { option ->
Row(verticalAlignment = Alignment.CenterVertically) {
RadioButton(
selected = (option == selected),
onClick = { selected = option }
)
Text(option)
}
}

适用场景

  • 性别选择、支付方式选择、任何互斥选项场景

⚠️ 注意

  • RadioButton 本身不包含文字,需要手动组合 Row + Text
  • 和传统的 RadioGroup 不同,Compose 中需要手动管理互斥逻辑(通过状态变量)
  • colors 可配置:selectedColorunselectedColordisabledSelectedColordisabledUnselectedColor

Slider —— 滑动条

作用

通过拖动滑块在连续范围内选择一个值。

核心属性

参数类型说明
valueFloat当前值
onValueChange(Float) -> Unit拖动回调
modifierModifier外观修饰
enabledBoolean是否可用,默认 true
valueRangeClosedFloatingPointRange<Float>取值范围,如 0f..100f
stepsInt分段数,0 表示连续,1 表示 1 段
colorsSliderColors颜色配置,SliderDefaults.colors()
onValueChangeFinished(() -> Unit)?拖动结束回调

示例

1
2
3
4
5
6
7
8
9
var sliderValue by remember { mutableStateOf(0.5f) }

Slider(
value = sliderValue,
onValueChange = { sliderValue = it },
valueRange = 0f..1f
)

Text("当前值:${"%.0f".format(sliderValue * 100)}%")

带刻度的 Slider

1
2
3
4
5
6
7
8
var volume by remember { mutableStateOf(5f) }

Slider(
value = volume,
onValueChange = { volume = it },
valueRange = 0f..10f,
steps = 9 // 10 个档位需要 9 个分段
)

适用场景

  • 音量调节、亮度调节、进度条、价格区间选择

⚠️ 注意

  • steps = 0 表示连续拖动,steps = n 表示分成 n+1 档
  • onValueChangeFinished 适合在拖动结束时触发保存或网络请求
  • 需要显示范围标签时,配合 Row + Text 放在 Slider 两端

Column —— 纵向布局

作用

子元素纵向依次排列。等同于传统 LinearLayout(orientation=vertical)

核心属性

参数类型说明
modifierModifier外观修饰
verticalArrangementArrangement.Vertical垂直排列方式(见下表)
horizontalAlignmentAlignment.Horizontal水平对齐方式:Start / CenterHorizontally / End
content@Composable ColumnScope.() -> Unit子元素内容

Arrangement.Vertical 常用值

效果
Arrangement.Top顶部对齐(默认)
Arrangement.Center垂直居中
Arrangement.Bottom底部对齐
Arrangement.SpaceBetween两端对齐,中间均匀留空
Arrangement.SpaceAround每个元素两侧有相同间距
Arrangement.SpaceEvenly所有间距相等
Arrangement.spacedBy(8.dp)每个元素之间固定间距

示例

1
2
3
4
5
6
7
8
9
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("第一行")
Text("第二行")
Text("第三行")
}

适用场景

  • 表单页面、设置列表、任何需要纵向排列内容的场景

⚠️ 注意

  • verticalArrangement 只在 Column 高度大于子元素总高度时生效
  • 子元素默认靠左对齐,通过 horizontalAlignment 控制水平位置
  • 使用 Modifier.weight(1f) 可以让子元素按比例分配剩余空间

Row —— 横向布局

作用

子元素横向依次排列。等同于传统 LinearLayout(orientation=horizontal)

核心属性

参数类型说明
modifierModifier外观修饰
horizontalArrangementArrangement.Horizontal水平排列方式(同 Column 中的 Arrangement 值,方向改为水平)
verticalAlignmentAlignment.Vertical垂直对齐方式:Top / CenterVertically / Bottom
content@Composable RowScope.() -> Unit子元素内容

示例

1
2
3
4
5
6
7
8
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text("左边")
Text("右边")
}

适用场景

  • 工具栏、操作栏、表单行、任何需要横向排列的场景

⚠️ 注意

  • horizontalArrangement 只在 Row 宽度大于子元素总宽度时生效
  • 子元素默认顶部对齐,通过 verticalAlignment 控制垂直位置
  • 常用 Modifier.weight(1f) 让文字填充剩余空间(搭配 TextOverflow.Ellipsis

Box —— 层叠布局

作用

子元素层叠排列,后写的盖在先写的上面。等同于传统 FrameLayout

核心属性

参数类型说明
modifierModifier外观修饰
contentAlignmentAlignment所有子元素的对齐方式,默认 TopStart
propagateMinConstraintsBoolean是否传递最小约束给子元素,默认 false
content@Composable BoxScope.() -> Unit子元素内容

子元素独立对齐

Box 内,子元素可通过 Modifier.align() 独立控制自己的对齐位置:

位置
Alignment.TopStart左上
Alignment.TopCenter上中
Alignment.TopEnd右上
Alignment.CenterStart左中
Alignment.Center正中
Alignment.CenterEnd右中
Alignment.BottomStart左下
Alignment.BottomCenter下中
Alignment.BottomEnd右下

示例

1
2
3
4
5
6
7
Box(
modifier = Modifier.size(200.dp),
contentAlignment = Alignment.Center
) {
Image(painter = painterResource(R.drawable.bg), contentDescription = null)
Text("盖在图片上的文字", color = Color.White)
}

不同位置叠加

1
2
3
4
5
Box(modifier = Modifier.fillMaxSize()) {
Text("左上角", modifier = Modifier.align(Alignment.TopStart))
Text("正中间", modifier = Modifier.align(Alignment.Center))
Text("右下角", modifier = Modifier.align(Alignment.BottomEnd))
}

适用场景

  • 图文叠加(文字盖在图片上)、角标(Badge)、加载覆盖层、水印

⚠️ 注意

  • Box 的大小由最大的子元素决定(除非指定了固定尺寸)
  • 子元素默认对齐左上角,通过 contentAlignment 统一设置或 Modifier.align() 单独设置
  • BoxScope 提供了 matchParentSize() 修饰符,让子元素匹配 Box 的大小

LazyColumn / LazyRow —— 列表控件

作用

高性能列表,自带回收复用机制,只渲染屏幕上可见的 item。替代传统 RecyclerView

核心属性

参数类型说明
modifierModifier外观修饰
stateLazyListState列表状态(滚动位置、首个可见项等)
contentPaddingPaddingValues列表内边距
reverseLayoutBoolean是否反转布局,默认 false
verticalArrangement / horizontalArrangementArrangement.Vertical / Arrangement.Horizontalitem 间距排列方式
flingBehaviorFlingBehavior滑动惯性行为
userScrollEnabledBoolean是否允许用户滚动,默认 true
contentLazyListScope.() -> Unit列表内容

LazyListScope 常用方法

方法说明
item { }添加单个 item
items(count) { index -> }添加 count 个 item
items(list) { item -> }遍历集合添加 item
itemsIndexed(list) { index, item -> }遍历集合(带索引)
stickyHeader { }粘性头部

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
val items = List(1000) { "第 ${it + 1} 项" }

LazyColumn {
items(items) { item ->
Text(
text = item,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
fontSize = 18.sp
)
Divider()
}
}

横向列表

1
2
3
4
5
6
7
8
9
10
11
12
LazyRow {
items(20) { index ->
Box(
modifier = Modifier
.size(100.dp)
.padding(8.dp)
.background(Color.Gray)
) {
Text("$index")
}
}
}

带头部的列表

1
2
3
4
5
LazyColumn {
item { Text("头部", fontSize = 24.sp) }
items(dataList) { item -> Text(item) }
item { Text("底部", fontSize = 12.sp) }
}

适用场景

  • 聊天列表、商品列表、新闻列表、任何数据量较大需要滚动的场景

⚠️ 注意

  • 不要LazyColumn 外套 ColumnRow,会导致性能问题和布局异常
  • LazyVerticalGrid 可实现网格列表,LazyHorizontalGrid 可实现横向网格
  • 使用 rememberLazyListState() 可程序化控制滚动位置
  • contentPadding + Arrangement.spacedBy() 可控制列表边距和 item 间距

Scaffold —— 页面骨架

作用

快速搭建标准 App 页面结构:顶部栏 + 内容区 + 底部栏 + 浮动按钮。

核心属性

参数类型说明
modifierModifier外观修饰
topBar@Composable () -> Unit顶部栏,通常放 TopAppBar
bottomBar@Composable () -> Unit底部栏,放 BottomAppBarNavigationBar
floatingActionButton@Composable () -> Unit浮动按钮,通常放 FloatingActionButton
floatingActionButtonPositionFabPositionFAB 位置:FabPosition.Center / FabPosition.End
snackbarHost@Composable () -> UnitSnackbar 宿主
containerColorColor内容区背景色
content@Composable (PaddingValues) -> Unit页面主体内容,必须在内容上加上 innerPadding

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Scaffold(
topBar = {
TopAppBar(
title = { Text("我的应用") },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Blue,
titleContentColor = Color.White
)
)
},
bottomBar = {
NavigationBar {
NavigationBarItem(
icon = { Icon(Icons.Default.Home, contentDescription = "首页") },
label = { Text("首页") },
selected = true,
onClick = { }
)
NavigationBarItem(
icon = { Icon(Icons.Default.Person, contentDescription = "我的") },
label = { Text("我的") },
selected = false,
onClick = { }
)
}
},
floatingActionButton = {
FloatingActionButton(onClick = { }) {
Icon(Icons.Default.Add, contentDescription = "添加")
}
}
) { innerPadding ->
Column(modifier = Modifier.padding(innerPadding)) {
Text("页面内容在这里")
}
}

TopAppBar 核心属性

参数类型说明
title@Composable () -> Unit标题内容
modifierModifier外观修饰
navigationIcon@Composable () -> Unit左侧导航图标(返回键)
actions@Composable RowScope.() -> Unit右侧操作按钮组
colorsTopAppBarColors颜色配置
scrollBehaviorTopAppBarScrollBehavior?滚动行为
参数类型说明
modifierModifier外观修饰
containerColorColor背景色
contentColorColor内容主色
tonalElevationDp色调高度
content@Composable RowScope.() -> Unit导航项内容

FloatingActionButton 核心属性

参数类型说明
onClick() -> Unit点击回调
modifierModifier外观修饰
shapeShape形状,默认 CircleShape
containerColorColor背景色
contentColorColor内容色
content@Composable () -> Unit内部内容

适用场景

  • 几乎任何需要标准 App 页面的场景(首页、设置、个人中心等)

⚠️ 注意

  • **必须使用 innerPadding**,否则内容会被 TopAppBar / BottomBar 遮挡
  • Scaffold 自身不滚动,列表内容需要放在 content 内部的 LazyColumn
  • BottomAppBarNavigationBar 的区别:前者是通用底部栏,后者专用于底部导航
  • FloatingActionButtonshape 默认圆形,可用 RoundedCornerShape(16.dp) 改为圆角矩形

Modifier 速查表

作用

Modifier 是所有 Compose 控件共用的外观修饰系统,控制控件的尺寸、边距、背景、形状、点击等。

常用 Modifier 速查

Modifier类别说明
fillMaxWidth()尺寸宽度填满父容器
fillMaxHeight()尺寸高度填满父容器
fillMaxSize()尺寸宽高都填满
size(width, height)尺寸固定宽高,如 size(100.dp, 50.dp)
width(dp)尺寸固定宽度,如 width(200.dp)
height(dp)尺寸固定高度,如 height(48.dp)
wrapContentWidth()尺寸宽度包裹内容
wrapContentHeight()尺寸高度包裹内容
wrapContentSize()尺寸包裹内容尺寸
padding(all)内边距四边相同内边距,如 padding(16.dp)
padding(horizontal, vertical)内边距水平和垂直内边距
padding(start, top, end, bottom)内边距分别设置四边内边距
background(color)外观背景色,如 background(Color.Red)
background(color, shape)外观带形状的背景色
clip(shape)外观裁剪形状,RoundedCornerShape(12.dp) / CircleShape
border(width, color)外观边框,border(1.dp, Color.Gray)
border(width, color, shape)外观带形状的边框
shadow(elevation, shape)外观阴影,shadow(4.dp, RoundedCornerShape(8.dp))
alpha(float)外观透明度,0f(全透明) ~ 1f(不透明)
clickable { }交互点击事件
combinedClickable(onClick, onLongClick)交互点击 + 长按
weight(float)布局按权重分配空间(Row/Column 内使用)
offset(x, y)布局偏移位置,不影响布局计算
align(alignment)布局在父容器中的对齐方式(Box 内使用)
scrollable(state, orientation)滚动使控件可滚动
verticalScroll(rememberScrollState())滚动垂直滚动(Column 内使用)
horizontalScroll(rememberScrollState())滚动水平滚动(Row 内使用)
animateContentSize()动画内容尺寸变化时自动动画过渡
testTag(string)测试测试标签

综合示例

1
2
3
4
5
6
7
8
9
10
11
Box(
modifier = Modifier
.size(100.dp)
.clip(RoundedCornerShape(12.dp))
.background(Color.Blue)
.border(2.dp, Color.White, RoundedCornerShape(12.dp))
.clickable { },
contentAlignment = Alignment.Center
) {
Text("点我", color = Color.White)
}

⚠️ 注意

  • Modifier 顺序很重要:先 paddingbackground,背景色包含 padding 区域;反之则不包含
  • 链式调用顺序是从外到内包裹的:Modifier.padding(16.dp).background(Color.Red) 等效于先包一层红色,再在红色内部加 16dp 边距
  • 同一个 Modifier 只能使用一次(如不能写两个 .padding()),但可以通过链式组合其他 Modifier