0

Main Activity:

override fun onCreate(savedInstanceState: Bundle?) {
    val splashScreen = installSplashScreen()
    super.onCreate(savedInstanceState)

    WindowCompat.setDecorFitsSystemWindows(window, false)

    setContent {
        ArchApp()
    }
}

Screen with toolbar:

Scaffold(
    topBar = {
        TopAppBar {
            Button(
                onClick = { },
                colors = ButtonDefaults.buttonColors(
                    containerColor = AppColor.BlueGray14,
                    contentColor = AppColor.White
                ),
                contentPadding = PaddingValues(8.dp)
            ) {
                Icon(
                    painter = painterResource(id = R.drawable.ic_menu),
                    contentDescription = "Open side menu"
                )
            }
        }
    },
) { innerPadding ->

App main composable:

AppDrawer(
    ...
) {
    AppNavGraph(
        startDestination = appStartScreen,
        navController = appState.navController,
        modifier = Modifier.fillMaxSize()
    )
}

enter image description here

Why TopAppBar ignores safe paddings? Isn't it supposed to add them when it's being used in Scaffold?

user25
  • 2,873
  • 2
  • 30
  • 66

1 Answers1

0

Was incorrect Material library :)

Fixed by replacing import androidx.compose.material.TopAppBar to import androidx.compose.material3.TopAppBar and also modified TopAppBar params

Scaffold(
    topBar = {
        TopAppBar(
            title = {},
            navigationIcon = {
                Button(
                    onClick = { },
                    colors = ButtonDefaults.buttonColors(
                        containerColor = AppColor.BlueGray14,
                        contentColor = AppColor.White
                    ),
                    contentPadding = PaddingValues(8.dp)
                ) {
                    Icon(
                        painter = painterResource(id = R.drawable.ic_menu),
                        contentDescription = "Open side menu"
                    )
                }
            }
        )
    },
) { innerPadding ->

I still keep old Material library for PullRefresh feature but may be Material 3 already have it as well :)

user25
  • 2,873
  • 2
  • 30
  • 66