Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Adding margins to navigation item in BottomNavigationView

kalabalik:

I have a BottomNavigationView which I instantiate like this:


BottomNavigationView navigationView = findViewById(R.id.bottom_navigation);
navigationView.setOnNavigationItemSelectedListener(this);

/menu/menu.xml looks like this:




android:id="@+id/first_id"
android:icon="@drawable/home_icon"
android:title="Item" />

android:id="@+id/second_id"
android:icon="@drawable/home_icon"
android:title="Item" />

android:id="@+id/third_id"
android:icon="@drawable/home_icon"
android:title="Item" />

android:id="@+id/fourth_id"
android:icon="@drawable/home_icon"
android:title="Item" />


And /drawable/home_icon looks like this:


android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
android:fillColor="#FFFFF0"
android:pathData="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"
android:strokeColor="#FFFFF0"
android:strokeWidth="1" />


As you can see, I have borders around the buttons of the navigation items, however, the borders touch each other. Therefore I would like to add a margin between the menu buttons. How can I do this?

As you can also see from the screenshot, I am preventing shifting mode. I do this by calling


BottomNavigationViewHelper.removeShiftMode(navigationView);

using code from here.

The borders around the buttons have been added like this:


int stateListDrawable = drawableStateLists.get(currentFragment);
navigationView.setItemBackgroundResource(stateListDrawable);

while stateListDrawable refers to a StateListDrawable which changes when a different menu button is pressed. The StateListDrawable refers to an xml selector which in turn refers to an xml shape like this, for example:



android:shape="rectangle">

android:width="2dp"
android:color="@color/intro"/>




Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Adding margins to navigation item in BottomNavigationView

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×