Android Studio 如何在Android上的BottomNavigationView中删除图标的边距?

2cmtqfgy  于 12个月前  发布在  Android
关注(0)|答案(1)|浏览(180)

我正试图删除Android上BottomNavigationView中图标的边距。我已经设法使用app:labelVisibilityMode=“unlabeled”删除了文本,但我似乎无法摆脱图标的默认边距。
下面是我的XML布局:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:labelVisibilityMode="unlabeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation_menu"/>

</androidx.constraintlayout.widget.ConstraintLayout>

这是我的菜单文件:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/reproductive"
        android:icon="@drawable/baseline_calendar_month_24"
        android:title="Dashboard"/>
    <item
        android:id="@+id/dashboard"
        android:icon="@drawable/baseline_info_24"
        android:title="Reprodução"/>
</menu>

尝试的方法:
1.我尝试在BottomNavigationView的XML中设置android:layout_margin=“0dp”,但边距仍然存在。
1.我尝试为BottomNavigationView使用自定义样式,在样式中设置android:layout_margin,但它也不起作用。
1.我在BottomNavigationView的XML中测试了android:padding=“0dp”和android:layout_margin=“0dp”,但边距仍然没有被删除。
我希望这些额外的细节有助于找到解决方案。如果有人有解决方案或其他建议,请分享。
我有什么

我想要

8yoxcaq7

8yoxcaq71#

我检查了BottomNavigationView的源代码,有一些参数是可自定义的。对于这个问题,我认为android:minHeight = 40dp(或其他小于默认值56dp的较小值)将降低底部导航视图的高度,并且框架也相应地减少了填充。让我知道这是否解决了问题。

相关问题