It is not clear how this happens in BottomNavigationView. I would like to learn from the more experienced. A programming language using java. As well as how to adjust the distance between the icons (buttons) in the BottomNavigationView. enter image description here

    1 answer 1

    In order to fill your BottomNavigationView , first, in the layout, specify for BottomNavigationView where to get resources with menu items using the app:menu attribute app:menu :

     <android.support.design.widget.BottomNavigationView android:id="@+id/bottom_navigation_view" ... app:menu="@menu/bottom_navigation_menu" /> 

    Your bottom_navigation_menu.xml with the described menu may look like this:

     <?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/action_first" android:enabled="true" android:icon="@drawable/ic_first" android:title="@string/text_first" app:showAsAction="ifRoom" /> <item android:id="@+id/action_second" android:enabled="true" android:icon="@drawable/ic_second" android:title="@string/text_second" app:showAsAction="ifRoom" /> <item android:id="@+id/action_third" android:enabled="true" android:icon="@drawable/ic_third" android:title="@string/text_third" app:showAsAction="ifRoom" /> </menu> 

    This is enough to fill the BottomNavigationView with buttons. Processing keystrokes will be as follows:

     BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_view); bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.action_first: break; case R.id.action_second: break; case R.id.action_third: break; } return true; } }); 

    The distance between the icons is controlled by the BottomNavigationView itself. When the number of menu items is more than three, the signatures of all items except the selected one are hidden. Also note that the maximum possible number of elements is 5.