I am trying to use a BottomNavigationView with Android Navigation to create a standard tabbed application with three fragments: StatusFragment, MapFragment, and AlertsFragment.
I have my main_activity.xml with a FragmentContainerView and BottomNavigationView defined as follows:
<?xml version="1.0" encoding="utf-8"?>
My main_nav_graph.xml:
<?xml version="1.0" encoding="utf-8"?>
.ui.status.StatusFragment"
android:label="StatusFragment" />
.ui.map.MapFragment"
android:label="MapFragment" />
.ui.alert.AlertsFragment"
android:label="AlertsFragment" />
.ui.main.MainActivity"
android:label="main_activity"
tools:layout="@layout/main_activity" />
And the associated main_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
In the onCreate method of my MainActivity, I configure navigation as follows:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
binding = MainActivityBinding.inflate(layoutInflater)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.mainNavHostFragment) as NavHostFragment
val navController = navHostFragment.navController
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.statusFragment,
R.id.mapFragment,
R.id.alertsFragment
)
)
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
NavigationUI.setupWithNavController(binding.bottomNavigationView, navController)
}
The tab bar is displayed as expected, but tapping on the buttons does not do anything. I've made sure that the ids defined in main_menu.xml match those in main_nav_graph.xml. For being such a basic component of navigation on mobile, getting this to work on Android is proving to be frustratingly difficult; any help would be greatly appreciated.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)