Android BottomNavigationView显示过大问题求助
针对你遇到的BottomNavigationView在真机/模拟器中显示过大的问题,尝试以下几种解决方案:
强制设置图标尺寸:导航栏高度会被菜单图标撑大,直接在BottomNavigationView上指定图标大小:
app:itemIconSize="24dp"(可根据需求调整数值)关闭默认最小高度:Material组件的BottomNavigationView默认带有最小高度限制,添加以下属性取消限制:
android:minHeight="0dp"检查菜单资源:打开
@menu/bottom_menu文件,确保每个item的图标没有使用过大的资源(比如高分辨率png),优先使用矢量图标并控制尺寸。调整主题样式:如果应用主题给BottomNavigationView附加了额外内边距或高度,可给组件单独设置基础样式:
style="@style/Widget.MaterialComponents.BottomNavigationView"
修改后的示例代码:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="0dp" android:layout_margin="0dp"> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="0dp" app:itemIconSize="24dp" app:labelVisibilityMode="unlabeled" android:layout_marginBottom="0dp" android:paddingBottom="0dp" app:menu="@menu/bottom_menu" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:elevation="0dp" /> </androidx.constraintlayout.widget.ConstraintLayout>
内容的提问来源于stack exchange,提问作者Mary
相关产品推荐
相关产品推荐

