Make sure you replace the nav_my_category_id (we will use this later) with a unique navigation id(No space in between the name) usually the category name will work. Also replace the @drawable/ic_add with your icon and My Category Name with your category name.
Now the first part is completed. Lets proceed to the second step.
Go to MainActivity.java file and find the code mentioned below
MainActivity.java
@OverridepublicbooleanonNavigationItemSelected(@NonNullMenuItem item) {int id =item.getItemId();if (id ==R.id.nav_home){viewPager.setCurrentItem(0,true);bottomNavigation.setCurrentItem(0); }elseif (id ==R.id.nav_categories){viewPager.setCurrentItem(1,true);bottomNavigation.setCurrentItem(1); }elseif(id==R.id.nav_offline){startActivity(new Intent(getApplicationContext(),OfflinePosts.class)); }elseif (id==R.id.nav_fb){openFbUrl("Google"); }elseif (id==R.id.nav_insta){openInstagram("Google"); }elseif (id==R.id.nav_tw){openTwitterUrl("Google"); }elseif (id==R.id.nav_yt){openYoutubeUrl("https://www.youtube.com/channel/UCNhT2txZHDfeIS0g7ZK7uRg"); }elseif (id==R.id.nav_web_url){openWebView("https://codecanyon.net/item/wordroid-full-wordpress-blog-app/19753667"); }if (id ==R.id.nav_about){openWebView("http://dev.itsanubhav.com/about-us/"); }elseif(id ==R.id.nav_privacy){openWebView("http://dev.itsanubhav.com/privacy-policy/"); }editor.apply();DrawerLayout drawer =findViewById(R.id.drawer_layout);drawer.closeDrawer(GravityCompat.START);returntrue; }
You need to add following file to the onNavigationItemSelected just before the editor.apply();
MainActivity.java
elseif (id ==R.id.nav_my_category_id){openCategory("Category Name",121);}
Make sure you change the nav_my_category_id to the id you added in the activity_main_drawer.xml. Change the Category Name with your category name and 121 with your category id.
Full Code Example
MainActivity.java
@OverridepublicbooleanonNavigationItemSelected(@NonNullMenuItem item) {int id =item.getItemId();if (id ==R.id.nav_home){viewPager.setCurrentItem(0,true);bottomNavigation.setCurrentItem(0); }elseif (id ==R.id.nav_categories){viewPager.setCurrentItem(1,true);bottomNavigation.setCurrentItem(1); }elseif(id==R.id.nav_offline){startActivity(new Intent(getApplicationContext(),OfflinePosts.class)); }elseif (id==R.id.nav_fb){openFbUrl("Google"); }elseif (id==R.id.nav_insta){openInstagram("Google"); }elseif (id==R.id.nav_tw){openTwitterUrl("Google"); }elseif (id==R.id.nav_yt){openYoutubeUrl("https://www.youtube.com/channel/UCNhT2txZHDfeIS0g7ZK7uRg"); }elseif (id==R.id.nav_web_url){openWebView("https://codecanyon.net/item/wordroid-full-wordpress-blog-app/19753667"); }if (id ==R.id.nav_about){openWebView("http://dev.itsanubhav.com/about-us/"); }elseif(id ==R.id.nav_privacy){openWebView("http://dev.itsanubhav.com/privacy-policy/"); }elseif (id ==R.id.nav_my_category_id){openCategory("Category Name",121); }editor.apply();DrawerLayout drawer =findViewById(R.id.drawer_layout);drawer.closeDrawer(GravityCompat.START);returntrue; }