Sae*_*adi 0 android android-jetpack android-jetpack-compose
我想将“Account”文本设置到TopAppBar的中心,并在TopAppBar的右侧添加一个图标,我该怎么做?
Scaffold(
scaffoldState = scaffoldState,
topBar = {
TopAppBar(
title = {
Text(
text = stringResource(R.string.account),
style = AppFont.PoppinsTypography.subtitle1
)
},
navigationIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_left),
contentDescription = "back", tint = AppColor.brandColor.BLUE_DE_FRANCE
)
}, actions = {
viewModel.navigateUp()
}, backgroundColor = AppColor.neutralColor.DOCTOR
)
},
)
Run Code Online (Sandbox Code Playgroud)
要将标题文本与 的中心对齐TopAppbar,
CenterAlignedTopAppBar( 标题 = { 文本( 文本 = stringResource(R.string.account), 样式 = AppFont.PoppinsTypography.subtitle1 ) }, )
并且actions属性应该在末尾添加可组合项。使用它在 的右侧添加一个图标TopAppBar。
例子,
actions = {
IconButton(onClick = { /*TODO*/ }) {
Icon(
imageVector = Icons.Rounded.ShoppingCart,
contentDescription = "cart",
)
}
},
Run Code Online (Sandbox Code Playgroud)
改成title这样,
title = {
Text(
text = stringResource(R.string.account),
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth(),
style = AppFont.PoppinsTypography.subtitle1
)
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4420 次 |
| 最近记录: |