Does anyone know how to remove paddings from navigationIcon and actions from TopAppBar? There are no paddings in the code, they come from who knows where. Yellow – TopAppBar, red – navigationIcon and actions. Tried windowInsets 0.dp for all for TopAppBar, doesn’t work. I’m talking about paddings between Yellow and Red.
@Composable
fun RootScaffold(
content: @Composable () -> Unit,
screenTitle: String,
topBarMenuChar: Char,
floatingActionButton: @Composable () -> Unit? = {}
) {
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
ModalNavigationDrawer(
drawerState = drawerState,
drawerContent = {
ModalDrawerSheet { /* Drawer content */ }
},
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black)
.paint(
painterResource(R.drawable.bg_app),
contentScale = ContentScale.Crop,
alpha = 0.12F
)
.background(MaterialTheme.colorScheme.secondary.copy(alpha = 0.12F))
.padding(horizontal = 20.dp)
) {
Scaffold(
containerColor = Color.Transparent,
topBar = { RootTopAppBar(screenTitle, topBarMenuChar) },
floatingActionButton = { floatingActionButton() }
) { paddingValues ->
Box(
modifier = Modifier
.padding(paddingValues)
) {
content()
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun RootTopAppBar(title: String, menuChar: Char) {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
TopAppBar(
colors = topAppBarColors(
containerColor = Color.Yellow
),
title = {
Text(
modifier = Modifier.padding(start = 12.dp).background(Color.Blue),
text = title
)
},
navigationIcon = {
Box(
modifier = Modifier
.size(31.dp)
.border(1.dp, MaterialTheme.colorScheme.onPrimary, CircleShape).background(Color.Red),
contentAlignment = Alignment.Center
) {
Text(
text = "$menuChar",
fontWeight = FontWeight.Bold
)
}
},
actions = {
Icon(
modifier = Modifier.background(Color.Red),
painter = painterResource(R.drawable.ic_plus),
contentDescription = "Localized description"
)
},
scrollBehavior = scrollBehavior,
)
}
1