3
  1. After upgrading to

    implementation 'com.google.android.material:material:1.1.0'
    

The Bottom Navigation View started behaving strangely on my phone. The height was set to 56dp and the icons were cropped and then when I set the height to "wrap_content" I get huge padding-bottom.

I tested it in different phones and different android versions and it behaves differently in all of them. (Android 10.0 with height set to wrap content behaves the same as Android 7.0 but with a smaller padding-bottom but still huge)

'Pictures or it didn't happen':

enter image description here

Code:

Main.xml

 <com.google.android.material.bottomnavigation.BottomNavigationView

    android:id="@+id/main_nav"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bottom_nav_bar"
    android:elevation="10dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    app:labelVisibilityMode="unlabeled"
    app:menu="@menu/nav_items">

</com.google.android.material.bottomnavigation.BottomNavigationView>

bottom_nav_bar.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorDarkBlack"/>
    <corners android:radius="1dp"
        android:topLeftRadius="30dp"
        android:topRightRadius="30dp"
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"/>

</shape>

Main.java

        BottomNavigationView bottomNavigationView = mMainNav.findViewById(R.id.main_nav);
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
    bottomNavigationView.setItemIconTintList(null);
    for (int i = 0; i < menuView.getChildCount(); i++) {
        final View iconView = menuView.getChildAt(i).findViewById(com.google.android.material.R.id.icon);
        final ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams();
        final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, displayMetrics);
        layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, displayMetrics);
        iconView.setLayoutParams(layoutParams);
    }
}

nav_items.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/nav_home"
    android:icon="@drawable/home"
    android:title=""
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/nav_blog"
    android:icon="@drawable/glasses"
    android:title=""
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/nav_workout"
    android:icon="@drawable/workout"
    android:title=""
    app:showAsAction="ifRoom" />
<item
    android:id="@+id/nav_settings"
    android:icon="@drawable/settings"
    android:title=""
    app:showAsAction="ifRoom" />

  1. What I've tried:

    • Changing back to 'com.google.android.material:material:1.0.0' fixes the issue completely but I need the new version.

    • Changing the style to legacy style="@style/Widget.Design.BottomNavigationView" as stated in documentation does nothing.

    • Playing with padding values just increases the crop

    • Tried <dimen name="design_bottom_navigation_height" tools:override="true">56dp</dimen> but it doesn't work also


I don't have a clue on what to do anymore does someone have any ideas for how can I solve this so it behaves the same in every phone?

Thanks in advance!

newbieCoder.pkg
  • 277
  • 2
  • 14
  • just a guess: what if you leave out the `android:title=""` from all items? I have a feeling that in one case it actually reserves space for the empty string and in the other it's treated as having no title. – Ivo Feb 17 '20 at 12:18
  • I tried removing the ```android:title=""``` and the issue remained. However, I tried to add the labels to see what the padding was. I used the tool "Show layout bounds" on my phone. What I discovered was that the extra padding is coming from the now hidden **phone navbar** as I'm using **Sticky Immersive Mode**. And it makes sense as the **Android 6.0** phone I used which presents the desired output has a physical navbar. So there must be some kind of conflict between immersive mode and the new BottomNavigationView. – newbieCoder.pkg Feb 17 '20 at 12:39

0 Answers0