com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener Java Examples
The following examples show how to use
com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java From AcgClub with MIT License | 4 votes |
@Override protected void initData() { setToolBar(mToolBar, getString(R.string.nav_news)); getAppVersionInfo(); getSupportActionBar().setDisplayHomeAsUpEnabled(false); toggle = new ActionBarDrawerToggle(this, drawerLayout, mToolBar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawerLayout.addDrawerListener(toggle); toggle.syncState(); if (loadFragments.get(RouterConstants.PATH_SCHEDULE_MAIN) == null) { loadMultipleRootFragment(R.id.main_content, 0, getTargetFragment(RouterConstants.PATH_SCHEDULE_MAIN), getTargetFragment(RouterConstants.PATH_COMIC_QIMIAO), getTargetFragment(RouterConstants.PATH_PICTURE_MAIN), getTargetFragment(RouterConstants.PATH_ACGNEWS_MAIN)); } bottomBar.setOnTabSelectListener(new OnTabSelectListener() { @Override public void onTabSelected(@IdRes int tabId) { String title = null; switch (tabId) { case R.id.nav_schedule: showFragment = RouterConstants.PATH_SCHEDULE_MAIN; title = getString(R.string.nav_schedule); break; case R.id.nav_comic: showFragment = RouterConstants.PATH_COMIC_QIMIAO; title = getString(R.string.nav_comic); break; case R.id.nav_news: showFragment = RouterConstants.PATH_ACGNEWS_MAIN; title = getString(R.string.nav_news); break; case R.id.nav_picture: showFragment = RouterConstants.PATH_PICTURE_MAIN; title = getString(R.string.nav_picture); break; /*case R.id.nav_fiction: showFragment = R.id.nav_fiction; title = getString(R.string.nav_fiction); break;*/ /*case R.id.nav_setting: showFragment = RouterConstants.PATH_SETTING; title = getString(R.string.nav_setting); break;*/ } showHideFragment(getTargetFragment(showFragment), getTargetFragment(hideFragment)); mToolBar.setTitle(title); hideFragment = showFragment; } }); //navigationView.getMenu().findItem(R.id.nav_news).setChecked(true); navigationView.setNavigationItemSelectedListener( new OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.nav_collection: RouterUtils.getInstance() .build(RouterConstants.PATH_COLLECTION) .navigation(); break; case R.id.nav_music: RouterUtils.getInstance() .build(RouterConstants.PATH_MUSIC_RANDOM) .navigation(); break; case R.id.nav_setting: RouterUtils.getInstance() .build(RouterConstants.PATH_SETTING) .navigation(); break; } //mToolBar.setTitle(item.getTitle()); drawerLayout.closeDrawer(GravityCompat.START); return true; } }); }