Som*_*der 3 android android-jetpack-compose
我无法弄清楚为什么要在 CenterAlignedTopAppBar 的顶部添加此填充,使用 Material2 效果很好并且大小为 56dp,material3 正在执行此操作。
这是一些显示我正在做什么的代码,我的可组合项包装在一个片段中。目前我正在使用一个列,我也尝试使用 Scaffold 得到相同的结果。
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return ComposeView(requireContext()).apply {
setContent {
val uiState = viewModel.uiState.collectAsState()
viewModel.setIntent(MapIntent.GetOneOrAll(id))
Column {
if (uiState.value.hasToolbar) {
CenterAlignedTopAppBar(
modifier = Modifier.fillMaxWidth().wrapContentHeight(),
title = {
Text(
text = uiState.value.toolbarTitle ?: "", maxLines = 1, overflow = TextOverflow.Ellipsis,
color = colorResource(id = R.color.white)
)
},
navigationIcon = {
IconButton(onClick = { /* doSomething() */ }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = null,
tint = colorResource(id = R.color.white)
)
}
},
actions = {
IconButton(onClick = { /* doSomething() */ }) {
Icon(
imageVector = Icons.Filled.Menu,
contentDescription = null,
tint = colorResource(id = R.color.white)
)
}
},
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = colorResource(id = R.color.colorPrimaryDark),
)
)
}
MapView(
modifier = Modifier.fillMaxSize(),
onMapClick = { viewModel.setIntent(MapIntent.OnClickMap) },
onMarkerClick = { viewModel.setIntent(MapIntent.OnClickMarker(it)) },
cameraPositionState = uiState.value.cameraPositionState,
markers = uiState.value.markers
)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
不知道为什么我需要指定这一点,但将插入设置为零解决了我的问题。
windowInsets = WindowInsets(
top = dimensionResource(id = R.dimen.size_0dp),
bottom = dimensionResource(id = R.dimen.size_0dp)
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1281 次 |
| 最近记录: |