0

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

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.