简体   繁体   中英

How to use jetpack navigation with bottomNavigationView in android java

how can i use android jet pack with BottomnavigationView java it only Kotline code out there even on google docs i am confused

   navigationUI.setupWithNavController(bottomNavigationView,Navigation.findNavController(this,R.id.nav_host_fragment));

navigationUI.setupWithNavController(bottomNavigationView,Navigation.findNavController(this,R.id.nav_host_fragment));

onclick on the menu icon using navigate through the screen drawn from the navgraph

You are doing it right. Just the id's of fragments in navigation graph xml file and the id's of menu items should be the same. So the navigation controller know which fragment to load.

val navController = findNavController(activity!!, R.id.bottomNavFragment)

val navHostFragment = childFragmentManager.findFragmentById(R.id.bottomNavFragment)!!

// set navigation graph
navController.setGraph(R.navigation.nav_graph_nav_bottom)
bottomNavigation.setupWithNavController(navController)

Kotlin is essentially same thing with Java, if you still get confused, my project can help you a little bit, the best demo of Jetpack is the android-sunflower - the official demonstration app of Android Jetpack, Although it is wrote in Kotlin, it can still implement by java.

In order to support Android Jetpack, I translated all kotlin implementations to Java, and added [app-java] module as the Java version of android-sunflower app, please check out android-sunflower-java .

There are many UseCases of Navigation , databinding , WorkManager , Room , etc. I'm sure you will have a better understanding of Navigation component if you have a look at android-sunflower-java project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM