Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 768
ngenge Avatar asked Jun 12 '19 16:06

ngenge


People also ask

How to remove the ActionBar?

If we want to remove the ActionBar only from specific activities, we can create a child theme with the AppTheme as it's parent, set windowActionBar to false and windowNoTitle to true and then apply this theme on an activity level by using the android:theme attribute in the AndroidManifest. xml file.

How to Hide ActionBar Android?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.


2 Answers

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)
like image 129
bikes Avatar answered Oct 17 '22 00:10

bikes


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()
like image 43
blackchalk Avatar answered Oct 17 '22 01:10

blackchalk