Over 3 items in the bottom navigation bar of Android

I am new to android and I am trying to create an application with more than three elements in the bottom navigation bar. I can display them, but they are collected at the end of the list, and only three are displayed correctly. Here is my code:

<android.support.design.widget.BottomNavigationView android:id="@+id/bottomNavigation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:elevation="15dp" android:layout_gravity="bottom" android:layout_alignParentBottom="true" app:menu="@menu/bottom_nav_items" /> 

Here is a view image: This is a snapshot.

I'm stuck, please help ..

+7
android android-layout bottomnavigationview
source share
3 answers

I'm not sure, but as far as I know, it is impossible to accompany more than three objects with the bottom panel without distorting the alignment. What you can do in any case is a linear layout with a horizontal orientation, and in this case, set these icons in the form of images, and then make their weight equal to 1.

Here is the code

 <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:layout_alignParentBottom="true" android:background="#fff"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="(YOUR IMAGE SOURCE)" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:layout_weight="1"/> 

And then other kinds of images like this.

+3
source share

You can use the method below to not get clustered menu items. You must call this method in the onCreate method, passing in a BottomNavigationView.

 // Method for disabling ShiftMode of BottomNavigationView private void disableShiftMode(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 updated item.setChecked(item.getItemData().isChecked()); } } catch (NoSuchFieldException e) { Log.e("BNVHelper", "Unable to get shift mode field", e); } catch (IllegalAccessException e) { Log.e("BNVHelper", "Unable to change value of shift mode", e); } } 
+14
source share
  <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="?android:attr/windowBackground" app:menu="@menu/navigation" /> navigation.xml(inside menu) <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/navigation_home" android:icon="@drawable/ic_home_black_24dp" android:title="@string/title_home" app:showAsAction="always|withText" android:enabled="true"/> inside oncreate method BottomNavigationView navigation = (BottomNavigationView)findViewById(R.id.navigation); BottomNavigationViewHelper.disableShiftMode(navigation);//Dont forgot this line public class BottomNavigationViewHelper { public static void disableShiftMode(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); //noinspection RestrictedApi item.setShiftingMode(false); // set once again checked value, so view will be updated //noinspection RestrictedApi item.setChecked(item.getItemData().isChecked()); } } catch (NoSuchFieldException e) { Log.e("BNVHelper", "Unable to get shift mode field", e); } catch (IllegalAccessException e) { Log.e("BNVHelper", "Unable to change value of shift mode", e); } } } 
+1
source share

All Articles