ngenge
ngenge

Reputation: 157

How to Set BottomNavigationView in AndroidX with No ActionBar

I am using Android architecture components with the Single Activity pattern on Android. The navigation pattern I am using is BottomNavigationView.I actually want the parent activity to have no ActionBar but setting my theme to be of type NoActionBar crashes the App. Setting Navigation in Activity has been done as below

val navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
    setOf(R.id.navigation_popular, R.id.navigation_top_rated, R.id.navigation_favorites)
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)

How do I set up bottom navigation to have no actionBar since I wish to have on of the some fragments with ActionBar, like CollapsingToolbarLayout?

Upvotes: 6

Views: 2327

Answers (2)

bikes
bikes

Reputation: 131

I think you found the solution but for the others, if you want to use the BottomNavigationView with the .NoActionBar theme so you should remove these lines:

val appBarConfiguration = AppBarConfiguration(
    setOf(R.id.navigation_popular, R.id.navigation_top_rated, R.id.navigation_favorites)
)
setupActionBarWithNavController(navController, appBarConfiguration)

Upvotes: 7

blackchalk
blackchalk

Reputation: 21

Using Android Navigation BottomNavigationView. Do not restrict activity with NoActionBar in manifest. Instead from your activity retrieve an instance of your support action bar and use its public method hide()

if (savedInstanceState == null) {
    setupBottomNavigationBar()

} // Else, need to wait for onRestoreInstanceState

supportActionBar?.hide()

Upvotes: 2

Related Questions