I have DrawerLayout and NavigationView. There are two fragments which are changed when I click on item in navigation drawer and that works well:
<fragment
android:id="#+id/nav_settings"
android:label="#string/menu_settings"
tools:layout="#layout/fragment_settings" />
<fragment
android:id="#+id/nav_themes"
android:label="#string/menu_themes"
tools:layout="#layout/fragment_themes" />
The problem is that I have several other items in the drawer menu that are not Fragments and I can not make them clickable:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group
android:id="#+id/group_1"
android:checkableBehavior="single">
<item
android:id="#+id/nav_settings"
android:icon="#drawable/ic_keyboard_settings"
android:title="#string/menu_settings" />
<item
android:id="#+id/nav_themes"
android:icon="#drawable/ic_theme"
android:title="#string/menu_themes" />
</group>
<group android:id="#+id/group_2">
<item
android:id="#+id/nav_developer_page"
android:icon="#drawable/ic_developer_page"
android:title="#string/menu_developer_page" />
<item
android:id="#+id/nav_privacy_policy"
android:icon="#drawable/ic_privacy_policy"
android:title="#string/menu_privacy_policy" />
</group>
</menu>
Here is the code:
setSupportActionBar(toolbar)
toggle = object : ActionBarDrawerToggle(this, drawer_layout, toolbar, 0, 0) {
override fun onDrawerClosed(drawerView: View) {
super.onDrawerClosed(drawerView)
syncState()
}
override fun onDrawerOpened(drawerView: View) {
super.onDrawerOpened(drawerView)
syncState()
}
}
toggle.syncState()
drawer_layout.addDrawerListener(toggle)
val navController = findNavController(R.id.nav_host_fragment)
appBarConfiguration = AppBarConfiguration(setOf(
R.id.nav_settings, R.id.nav_themes, R.id.nav_developer_page), drawer_layout)
nav_view.setupWithNavController(navController)
toggle.syncState()
When I set NavigationItemSelectedListener it breaks navigation for Fragments.
How can I make those two items clickable and call a function?
The solution is to get the menu item from the navigation view and set a click listener:
val signoutMenuItem = binding.nvNavigationDrawerNavigationView.menu.findItem(id.navigation_drawer_menu_sign_out)
signoutMenuItem.setOnMenuItemClickListener {
navigationDrawerMainActivityViewModel.signOut()
true
}
and do not include non-fragment items in AppBarConfiguration:
appBarConfiguration = AppBarConfiguration(
setOf(
id.drawerFragmentX,
id.drawerFragmentY,
//id.navigation_drawer_menu_sign_out <- Do NOT include
), drawerLayout
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
This solution is identical to https://stackoverflow.com/a/59451345/5189200.
Xavi
Related
I am using fragment and in that fragment i have ViewPager and in ViewPager i have added two fragments.when i open the app Everything works fine but my status bar becomes black and to see the icon i need to scroll down and this is happening in android 11,below android 11 Eveything working fine.now please let me know how to fix it...please don't ignore this and answer should be in Kotlin if Possible
I am attaching the code for it also
Main Activity:
class dashact : AppCompatActivity() {
lateinit var toolbar: Toolbar
lateinit var coordinator: CoordinatorLayout
lateinit var navigationdrawer: NavigationView
lateinit var drawerLayout: DrawerLayout
var nameofuser :String?="jdghjg"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dashact)
toolbar = findViewById(R.id.toolbar)
coordinator = findViewById(R.id.coordinator)
navigationdrawer = findViewById(R.id.navigationview)
drawerLayout = findViewById(R.id.drawerlayout)
actionbar()
var toggle = ActionBarDrawerToggle(
this#dashact,
drawerLayout,
R.string.open,
R.string.close
)
toggle.syncState()
drawerLayout.addDrawerListener(toggle)
hideSystemBars()
navigtiontitle("home")
supportFragmentManager.beginTransaction()
.replace(R.id.frame, frag1())
.commit()
drawerLayout.closeDrawers()
navigationdrawer.setNavigationItemSelectedListener {
if (it.isChecked==true){
it.isCheckable=true
}else{
it.isCheckable=false
}
when (it.itemId) {
R.id.home -> {
navigtiontitle("home")
supportFragmentManager.beginTransaction()
.replace(R.id.frame, frag1())
.commit()
drawerLayout.closeDrawers()
}
R.id.fav ->{
navigtiontitle("Favourites")
supportFragmentManager.beginTransaction()
.replace(R.id.frame,Viewpager2())
.commit()
drawerLayout.closeDrawers()
}
R.id.privacy ->{
navigtiontitle("Privacy Policies")
supportFragmentManager.beginTransaction()
.replace(R.id.frame,privacy())
.commit()
drawerLayout.closeDrawers()
}
R.id.details ->{
navigtiontitle("My Details")
supportFragmentManager.beginTransaction()
.replace(R.id.frame,MyFrag())
.commit()
drawerLayout.closeDrawers()
}
}
return#setNavigationItemSelectedListener true
}
}
fun navigtiontitle(title: String) {
supportActionBar?.title = title
}
fun actionbar() {
super.setSupportActionBar(toolbar)
supportActionBar?.title = "Bookhub"
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> drawerLayout.openDrawer(GravityCompat.START)
}
return super.onOptionsItemSelected(item)
}
fun hideSystemBars() {
val windowInsetsController =
ViewCompat.getWindowInsetsController(window.decorView) ?: return
// Configure the behavior of the hidden system bars
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Hide both the status bar and the navigation bar
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
}
}
xml of main activity:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerlayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:elevation="0dp" >
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
/>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:headerLayout="#layout/headers"
app:menu="#menu/icons"
android:layout_gravity="start"/>
</androidx.drawerlayout.widget.DrawerLayout>
themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Test" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item> //for action bar
<item name="colorPrimaryVariant">#color/white</item> //can use to set status bar
<item name="colorOnPrimary">#color/purple_200</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">#color/purple_200</item>
<!-- Customize your theme here. -->
</style>
<style name="splashs" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:statusBarColor" tools:targetApi="l">#color/purple_200</item>
</style>
</resources>
You are hiding your system bars(status and navigation) in hideSystemBars() method. You are getting a black status bar probably due to a display cutout.
Find more about supporting display cutout here
I have created Navigation Drawer Activity using Android Studio project template and added few menu items programatically and set the item selected listener to navigate to destination fragment.
Here what I am trying to do is clicking on each menu item added above should open the same destination fragment say HomeFragment but with different arguments so that I can reuse the layout.
So far it is working great with only one problem that the menu items are not highlighting correctly and Home item is always checked. I think this is because I have added the self link to home fragment. Is there any way to fix this?
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navController = Navigation.findNavController(this, R.id.nav_host_fragment);
// Adding menu items
Menu menu = navigationView.getMenu();
SubMenu labels = menu.addSubMenu("Labels");
labels.add(R.id.group_labels, 201, 201, "Label 1").setIcon(R.drawable.ic_menu_gallery);
labels.add(R.id.group_labels, 202, 202, "Label 2").setIcon(R.drawable.ic_menu_gallery);
navigationView.invalidate();
appBarConfig = new AppBarConfiguration.Builder(R.id.home)
.setDrawerLayout(drawer)
.build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfig);
NavigationUI.setupWithNavController(navigationView, navController);
// Navigation item click listener
navigationView.setNavigationItemSelectedListener(item -> {
if (item.getGroupId() == R.id.group_labels) {
HomeFragmentDirections.ActionHomeSelf action = HomeFragmentDirections.actionHomeSelf();
action.setLabel(item.getTitle().toString());
navController.navigate(action);
}
navigationView.setCheckedItem(item.getItemId()); // Not working
NavigationUI.onNavDestinationSelected(item, navController);
drawer.closeDrawer(GravityCompat.START);
return true;
});
}
mobile_navigation.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mobile_navigation"
app:startDestination="#+id/home">
<fragment
android:id="#+id/home"
android:label="#string/menu_home"
android:name=".fragments.HomeFragment"
tools:layout="#layout/fragment_home">
<argument
android:name="label"
app:argType="string"
android:defaultValue="default label" />
<action
android:id="#+id/action_home_self"
app:destination="#id/home"
app:launchSingleTop="false">
</action>
<action
android:id="#+id/action_home_to_blank"
app:destination="#id/blankFragment" />
</fragment>
<fragment
android:id="#+id/blankFragment"
android:name=".BlankFragment"
android:label="fragment_blank"
tools:layout="#layout/fragment_blank" />
</navigation>
activity_main_drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:icon="#drawable/ic_menu_camera"
android:orderInCategory="0"
android:title="#string/menu_home" />
<item
android:id="#+id/blankFragment"
android:icon="#drawable/ic_menu_camera"
android:orderInCategory="0"
android:title="#string/hello_blank_fragment" />
</group>
<item
android:orderInCategory="200"
android:title="#string/drawer_menu_group_labels">
<menu>
<group
android:id="#+id/group_labels"
android:checkableBehavior="single" />
</menu>
</item>
<item
android:orderInCategory="300"
android:title="#string/drawer_menu_group_pages">
<menu>
<group
android:id="#+id/group_pages"
android:checkableBehavior="single" />
</menu>
</item>
</menu>
I've been trying to figure out how the default Navigation Drawer Activity template came with Android Studio navigates between different fragments. I understand that this menu is an implementation using AndroidX navigation component and navigation graph, but I just cannot understand how each menu item is mapped to its corresponding fragment. I don't see any listener or onNavigationItemSelected() etc. Can someone explain how the mapping between menuItem and corresponding fragment was achieved?
MainActivity.java:
public class MainActivity extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
mAppBarConfiguration = new AppBarConfiguration.Builder(
navController.getGraph())
.setDrawerLayout(drawer)
.build();
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
}
menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_menu_camera"
android:title="#string/menu_home" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="#string/menu_gallery" />
<item
android:id="#+id/nav_slideshow"
android:icon="#drawable/ic_menu_slideshow"
android:title="#string/menu_slideshow" />
</group>
</menu>
nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mobile_navigation"
app:startDestination="#+id/nav_home">
<fragment
android:id="#+id/nav_home"
android:name="com.buzzz.myapplication.ui.home.HomeFragment"
android:label="#string/menu_home"
tools:layout="#layout/fragment_home">
<action
android:id="#+id/action_HomeFragment_to_HomeSecondFragment"
app:destination="#id/nav_home_second" />
</fragment>
<fragment
android:id="#+id/nav_home_second"
android:name="com.buzzz.myapplication.ui.home.HomeSecondFragment"
android:label="#string/home_second"
tools:layout="#layout/fragment_home_second">
<action
android:id="#+id/action_HomeSecondFragment_to_HomeFragment"
app:destination="#id/nav_home" />
<argument
android:name="myArg"
app:argType="string" />
</fragment>
<fragment
android:id="#+id/nav_gallery"
android:name="com.buzzz.myapplication.ui.gallery.GalleryFragment"
android:label="#string/menu_gallery"
tools:layout="#layout/fragment_gallery" />
<fragment
android:id="#+id/nav_slideshow"
android:name="com.buzzz.myapplication.ui.slideshow.SlideshowFragment"
android:label="#string/menu_slideshow"
tools:layout="#layout/fragment_slideshow" />
</navigation>
Thank you very much.
As per the Update UI components with NavigationUI documentation, the setupWithNavController() methods hook up UI elements (such as your NavigationView) with the NavController.
Looking at the setupWithNavController() Javadoc:
Sets up a NavigationView for use with a NavController. This will call onNavDestinationSelected when a menu item is selected. The selected item in the NavigationView will automatically be updated when the destination changes.
So internally, this is setting up the appropriate listeners - both on the NavigationView to handle menu selections and on the NavController to update the selected item when the current destination changes.
Looking at the onNavDestinationSelected() Javadoc, it becomes clear how the menu items and navigation graph destinations are matched:
Importantly, it assumes the menu item id matches a valid action id or destination id to be navigated to.
So clicking on a menu item with android:id="#+id/nav_home" will navigate to the destination with android:id="#+id/nav_home".
I am using navigation jetpack and have set up navigation drawer. Every thing works fine. But the problem is I want to show a toast when user clicks "nav_share" but it is not showing...
here is how i made navigation drawer
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_plan, R.id.navigation_notifications)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
my menu for navigation drawer is
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_menu_camera"
android:title="#string/menu_home" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="#string/menu_gallery" />
<item
android:id="#+id/nav_slideshow"
android:icon="#drawable/ic_menu_slideshow"
android:title="#string/menu_slideshow" />
<item
android:id="#+id/nav_tools"
android:icon="#drawable/ic_menu_manage"
android:title="#string/menu_tools" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#drawable/ic_menu_share"
android:title="#string/menu_share" />
<item
android:id="#+id/nav_send"
android:icon="#drawable/ic_menu_send"
android:title="#string/menu_send" />
</menu>
</item>
</menu>
finally:
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
int id = menuItem.getItemId();
if (id == R.id.nav_share)
Toast.makeText(LauncherActivity.this, "Click", Toast.LENGTH_SHORT).show();
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
i want that click toast...i cannot see what am i missing....
if any one wants the answer..i did some research and finally found a solution to it...hope it helps....
NavigationView navigationView = findViewById(R.id.nav_view);
MenuItem shareItem = navigationView.getMenu().findItem(R.id.nav_share);
shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(LauncherActivity.this, "click", Toast.LENGTH_SHORT).show();
//do as you want with the button click
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
});
Use this
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.bringToFront()
navigationView.setNavigationItemSelectedListener(this);
I also had your problem and came up with the solution
NavController navController = Navigation.findNavController(this, R.id.nav_host_home);
NavigationUI.setupWithNavController(navigationView, navController);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
int id = menuItem.getItemId();
if (id == R.id.nav_share) {
Toast.makeText(getApplicationContext(), "nav_share", Toast.LENGTH_SHORT).show();
}
NavigationUI.onNavDestinationSelected(menuItem, navController);
drawerLayout.closeDrawer(Gravity.RIGHT);
return true;
}
});
In case if anyone is still searching for the answer as to how we can tie up navigation destinations and also handle click on menu items of the navigation drawer, it has been answered here: https://stackoverflow.com/a/57846680/3283350
Android Jetpack Navigation - Custom Action with Drawer Item
Simple step and easy
class MainActivity : AppCompatActivity(),NavigationView.OnNavigationItemSelectedListener{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val navView: NavigationView = binding.navView
navController = findNavController(R.id.nav_host_fragment_content_main)
navView.setNavigationItemSelectedListener(this)
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
val url: String? = when (item.itemId) {
R.id.nav_privacy_policy -> MenuItemUrl.PRIVACY_POLICY
R.id.nav_term_condition -> MenuItemUrl.TERM_AND_CONDITION
R.id.nav_contact_us -> MenuItemUrl.CONTACT_US
R.id.nav_feedback -> MenuItemUrl.FEEDBACK
R.id.nav_help_support -> MenuItemUrl.HELP_AND_SUPPORT
R.id.nav_faq -> MenuItemUrl.FAQ
R.id.nav_about_us -> MenuItemUrl.ABOUT_US
else -> null
}
if (url != null) Methods.openBrowser(this#MainActivity, url) // Do anything here ex. show toast etc.
NavigationUI.onNavDestinationSelected(item, navController)
drawerLayout.closeDrawer(GravityCompat.START)
return true
}
}
I have a navigation menu which looks like this -
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_home"
android:title="Home" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_logout"
android:title="Logout" />
<item
android:id="#+id/choose_bus"
android:title="Choose a bus">
<menu>
<group
android:id="#+id/group_select_bus"
android:checkableBehavior="single">
<!--<item-->
<!--android:id="#+id/menu_option1"-->
<!--android:title="Bus 1" />-->
<!--<item-->
<!--android:id="#+id/menu_option2"-->
<!--android:title="Bus 2" />-->
</group>
</menu>
</item>
I want to add menu_option1 and menu_option2 dynamically from the activity. I tried this but nothing adding -
#Override
public boolean onNavigationItemSelected(MenuItem item) {
NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
Menu menu = navView.getMenu();
MenuItem item1 = menu.getItem(2);
SubMenu subMenu = item1.getSubMenu();
subMenu.add("Bus 1");
subMenu.add("Bus 2");
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Try some thing like this
Menu menu = navView.getMenu();
menu.add(R.id.group_select_bus,Menu.NONE,Menu.NONE,Youritem);
Try this:
MenuItem item = mNavigationView.getMenu().getItem(2);
item.getSubMenu().add(R.id.group_select_bus, id, Menu.NONE, "Youritem");
Another approach is to add all items in navigation menu and then change their visibility on specific activity or fragment, like
MenuItem item = mNavigationView.getMenu().getItem(5);
item.setVisible(false);
Seems a little late to answer. There is workaround/hack for this. No need to add list. Just add this little line above your code. It surely works.
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.candidates -> {
binding.navSideView.post {
navSideView.menu.findItem(R.id.candidateManagement).isVisible = !navSideView.menu.findItem(R.id.candidateManagement).isVisible
}
}
}
return true
}
You need to add navigationview.post Runnable before changing visibility. It will update the menu. It works with group too. :)