底部导航视图没有响应

Bottom Navigation View not responsive

我需要 BottomNavigationView 响应。当我使用 Nexus 4 it has the exact measurement, but with Nexus 6 时,它不会。有什么想法吗?

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    app:itemIconTint="@drawable/selector"
    app:itemTextColor="@color/colorPrimary"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/navigation"/>

layout_height 属性设置为 wrap_content 而不是 match_parent:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" //modify this line
    android:layout_gravity="bottom"
    app:itemIconTint="@drawable/selector"
    app:itemTextColor="@color/colorPrimary"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/navigation"/>

因为身高是matching_parent!!所以这取决于父级是如何组成和调整视图的,对于这种情况最好有一个固定值宽度或设置为 wrap_content 但是你必须注意图标的大小!

如果您谈论的是宽度与父级不匹配,请检查 。您必须通过将其颜色设置为与项目相同的颜色来玩弄背景

 android:background="@color/bottom_view_color"
 app:itemBackground="@color/bottom_view_color"

使用 BottomNavigationView 高度作为 android:layout_height="wrap_content"android:layout_height="56dp".

参见 documentation 关于 height