I'm having some trouble figuring out why this padding is being added at the top of my CenterAlignedTopAppBar, using Material2 works just fine and has a size of 56dp, material3 is doing this.
Here is some code showing what I'm doing, my composable is wrapped in a fragment. Currently I'm using a column, I tried with Scaffold as well with the same result.

@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
)
}
}
}
}
Not sure why I needed to specify this, but setting insets to zero fixed my problem.
windowInsets = WindowInsets(
top = dimensionResource(id = R.dimen.size_0dp),
bottom = dimensionResource(id = R.dimen.size_0dp)
),
Seems like some parent composable has additional modifier like .statusBarsPadding() or .systemBarsPadding() or the .padding(it) from Scaffold composable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With