You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
//Global DeclarationSNavigationDrawersNavigationDrawer;ClassfragmentClass;publicstaticFragmentfragment;//Inside onCreate()sNavigationDrawer =findViewById(R.id.navigationDrawer);//Creating a list of menu ItemsList<MenuItem>menuItems =newArrayList<>();//Use the MenuItem given by this library and not the default one.//First parameter is the title of the menu item and then the second parameter is the image which will be the background of the menu item.menuItems.add(newMenuItem("News",R.drawable.news_bg));menuItems.add(newMenuItem("Feed",R.drawable.feed_bg));menuItems.add(newMenuItem("Messages",R.drawable.message_bg));menuItems.add(newMenuItem("Music",R.drawable.music_bg));//then add them to navigation drawersNavigationDrawer.setMenuItemList(menuItems);fragmentClass =NewsFragment.class;try {fragment = (Fragment)fragmentClass.newInstance(); }catch (Exceptione) {e.printStackTrace(); }if (fragment !=null) {FragmentManagerfragmentManager =getSupportFragmentManager();fragmentManager.beginTransaction().setCustomAnimations(android.R.animator.fade_in,android.R.animator.fade_out).replace(R.id.frameLayout,fragment).commit(); }//Listener to handle the menu item click. It returns the position of the menu item clicked. Based on that you can switch between the fragments.sNavigationDrawer.setOnMenuItemClickListener(newSNavigationDrawer.OnMenuItemClickListener() {@OverridepublicvoidonMenuItemClicked(intposition) {System.out.println("Position "+position);switch (position){case0:{fragmentClass =NewsFragment.class;break; }case1:{fragmentClass =FeedFragment.class;break; }case2:{fragmentClass =MessagesFragment.class;break; }case3:{fragmentClass =MusicFragment.class;break; } }//Listener for drawer events such as opening and closing.sNavigationDrawer.setDrawerListener(newSNavigationDrawer.DrawerListener() {@OverridepublicvoidonDrawerOpened() { }@OverridepublicvoidonDrawerOpening(){ }@OverridepublicvoidonDrawerClosing(){System.out.println("Drawer closed");try {fragment = (Fragment)fragmentClass.newInstance(); }catch (Exceptione) {e.printStackTrace(); }if (fragment !=null) {FragmentManagerfragmentManager =getSupportFragmentManager();fragmentManager.beginTransaction().setCustomAnimations(android.R.animator.fade_in,android.R.animator.fade_out).replace(R.id.frameLayout,fragment).commit(); } }@OverridepublicvoidonDrawerClosed() { }@OverridepublicvoidonDrawerStateChanged(intnewState) {System.out.println("State "+newState); } }); } });
MIT LicenseCopyright (c) 2018 Shrikanth RaviPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.