Reputation: 21
I would develop an android app with Single Activity and Two Fragments (LoginFragment and HomeFragment) with Navigation Drawer using Navigation Graph.
When I had add a Navigationdrawer
in my activity it is visible in LoginFragment
but I want to display hamburger icon only in HomeFragment
not LoginFragment
.
How to add a navigation drawer in activity without add it to LoginFragment
I had tried to hide a toolbar
val navController=this.findNavController(R.id.nav_host_fragment)
navController.addOnDestinationChangedListener{ nc: NavController, nd: NavDestination, _->
if(nd.id==nc.graph.startDestination){
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
binding.toolBar.visibility = View.GONE
}else{
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
NavigationUI.setupActionBarWithNavController(this,navController,drawerLayout)
binding.toolBar.visibility = View.VISIBLE
}
I want to display hamburger icon only in HomeFragment
not LoginFragment
Upvotes: 0
Views: 1161
Reputation: 237
I think you're using Kotlin. But I don't think it will be different from the method in Java. You can convert from Java to Kotlin. That's what I did in java.
((AppCompatActivity) getActivity()).getSupportActionBar().hide(); // to hide toolbar
((AppCompatActivity) getActivity()).getSupportActionBar().show(); //to show toolbar
You need use this codes in fragments. For example you can set ...hide(); method in onCreateView method of LoginFragment, after that you can set ...show(); method in oncreateView of HomeFragment.
Upvotes: 1
Reputation: 71
You can create functions for hide and show navigation drawer icon in your activity and call these functions in your respective fragments onCreateView
Upvotes: 0