Updated 15 September 2017
Before starting this blog you should know the BottomNavigationView in Android. So First read our previous blog on the BottomNavigationView,
Ok, You have read the above blog. So we can start now.
Actually, when you use the more then 4 items in BottomNavigationView then Android automatically enable the shift mode.
Create a class named BottomNavigationViewHelper
12345678910111213141516171819202122 class BottomNavigationViewHelper {static void removeShiftMode(BottomNavigationView view) {BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);try {Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");shiftingMode.setAccessible(true);shiftingMode.setBoolean(menuView, false);shiftingMode.setAccessible(false);for (int i = 0; i < menuView.getChildCount(); i++) {BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);item.setShiftingMode(false);// set once again checked value, so view will be updateditem.setChecked(item.getItemData().isChecked());}} catch (NoSuchFieldException e) {Log.e("ERROR NO SUCH FIELD", "Unable to get shift mode field");} catch (IllegalAccessException e) {Log.e("ERROR ILLEGAL ALG", "Unable to change value of shift mode");}}}
and pass your BottomNavView to this function,
12 BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
Done. Now run the application and you will find the shift mode has been disabled.
If you have any doubt on this blog, please ask in comments. And stay updated and stay super.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
4 comments