BottomNavigationView
的默认图标大小为24dp。
看起来,您将
BottomNavigationView
的高度设置得足够小。在这种情况下,如果您想降低 BottomNavigationView
的高度,您还应该更改该项目的图标大小。
基本上,您可以在 XML 中使用以下功能。
app:itemIconSize="12dp"
所以,你的
BottomNavigationView
看起来像这样:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:background="@color/black"
android:id="@+id/bottomNavigationView"
android:layout_height="40dp"
android:layout_width="match_parent"
app:itemIconSize="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
我找到了!它与导航栏填充或大小无关。 问题实际上是在活动的 onCreate 方法内运行的自动生成的代码。转到设置导航栏的 Activity 并删除以下代码:
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
空白将会消失。
之前: 之前
之后:之后