Hieu Le
Hieu Le

Reputation: 101

How to change topBar corresponding screen in Jetpack Compose

I have a Scaffold like this:

Scaffold(
   topBar = {
       TopBar(...)
   },
   bottomBar = {
       BottomNavigationBar(...)
   }
) {
    NavHost(...)
}

What is the best way to change TopBar when I navigate to another screen?

Upvotes: 10

Views: 2883

Answers (1)

sovanrothaa
sovanrothaa

Reputation: 1042

There are two possible ways to go:

  1. Observing currentScreen and use when inside topBar and change it according to that

  2. Put topbar inside the screen it belongs to.

For me prefer the second one since it's not shared with each other, there's no reason to use ugly when statement for it.

Upvotes: 2

Related Questions