Home > Blockchain >  How to make TopAppBar navigationIcon disapear?
How to make TopAppBar navigationIcon disapear?

Time:04-24

Some of my screens do not need the drawer so I want the navigation icon not to show on the topbar. With the following code, I made the icon not shown but the space is still kept for the icon. How can I eliminate it?

TopAppBar(
    title = {
        Text(text = title,
            textAlign = TextAlign.Start,
            fontSize = 18.sp) },
    actions = { TopbarActions()},
    navigationIcon = {
        if (needDrawer) {
            IconButton(onClick = {
            }) {
                Icon(Icons.Filled.Menu, "")
            }
        } else Spacer(Modifier.width(1.dp))
    },
)

CodePudding user response:

You're creating an empty view, but you need to let TopAppBar know that there should be no view.

Pass null to navigationIcon like this:

TopAppBar(
    navigationIcon = if (needDrawer) {
        @Composable {
            IconButton(onClick = {
            }) {
                Icon(Icons.Filled.Menu, "")
            }
        }
    } else null
)
  • Related