唯客微博客

专注于计算机,嵌入式领域的技术

0%

Jetpack Compose组件-应用栏(AppBar)

Jetpack Compose组件-应用栏(AppBar)

顶部应用栏(TopAppBar)

Chip(小标签)类似于淘宝的历史搜索标签。

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
@Composable
fun TopAppBar(
// 修饰符
modifier: Modifier = Modifier,
// 背景颜色
backgroundColor: Color = MaterialTheme.colors.primarySurface,
// 内容颜色
contentColor: Color = contentColorFor(backgroundColor),
// 高度(阴影)
elevation: Dp = AppBarDefaults.TopAppBarElevation,
// 内容边距
contentPadding: PaddingValues = AppBarDefaults.ContentPadding,
content: @Composable RowScope.() -> Unit
): Unit

@Composable
fun TopAppBar(
// 标题
title: @Composable () -> Unit,
// 修饰符
modifier: Modifier = Modifier,
// 导航图标
navigationIcon: (@Composable () -> Unit)? = null,
// 右侧动作按钮
actions: @Composable RowScope.() -> Unit = {},
// 背景颜色
backgroundColor: Color = MaterialTheme.colors.primarySurface,
// 内容颜色
contentColor: Color = contentColorFor(backgroundColor),
// 高度(阴影)
elevation: Dp = AppBarDefaults.TopAppBarElevation
): Unit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
TopAppBar(
title = { Text("Simple TopAppBar") },
navigationIcon = {
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Menu, contentDescription = null)
}
},
actions = {
// RowScope here, so these icons will be placed horizontally
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Favorite, contentDescription = "Localized description")
}
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Favorite, contentDescription = "Localized description")
}
}
)

底部应用栏(BottomAppBar)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Composable
fun BottomAppBar(
// 修饰符
modifier: Modifier = Modifier,
// 背景颜色
backgroundColor: Color = MaterialTheme.colors.primarySurface,
// 内容颜色
contentColor: Color = contentColorFor(backgroundColor),
// 底部应用栏剪切形状, 在Scaffold中使用时,可将浮动按钮嵌入应用栏
cutoutShape: Shape? = null,
// 高度(阴影)
elevation: Dp = AppBarDefaults.BottomAppBarElevation,
// 内容边距
contentPadding: PaddingValues = AppBarDefaults.ContentPadding,
content: @Composable RowScope.() -> Unit
): Unit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BottomAppBar(cutoutShape = CircleShape) {
// Leading icons should typically have a high content alpha
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.high) {
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Menu, contentDescription = "Localized description")
}
}
// The actions should be at the end of the BottomAppBar. They use the default medium
// content alpha provided by BottomAppBar
Spacer(Modifier.weight(1f, true))
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Favorite, contentDescription = "Localized description")
}
IconButton(onClick = { /* doSomething() */ }) {
Icon(Icons.Filled.Favorite, contentDescription = "Localized description")
}
}
-------------本文结束感谢您的阅读-------------

本文标题:Jetpack Compose组件-应用栏(AppBar)

文章作者:Vinx

发布时间:2023年01月15日 - 09:21

最后更新:2023年09月19日 - 08:41

原始链接:https://blog.vinkvin.com/post/78/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。