BottomNavigationView在左侧添加额外的空间

问题描述 投票:0回答:1

嗨,我有一个BottomNavigationView,但是它在开始处添加了默认空间。下面是我的代码。

XML:

<?xml version="1.0" encoding="utf-8"?>
<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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:textAlignment="center"
    android:textSize="25dp"
    android:id="@+id/message"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"
    android:text="Home"
    />


<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id="@+id/app_bar_layout"
    >

    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/home_toolbar"
        >

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:itemBackground="@android:color/holo_green_dark"
            app:labelVisibilityMode="unlabeled"
            app:menu="@menu/bottom_nav_menu" />

    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>

这是我的菜单:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:id="@+id/navigation_home"
    android:icon="@drawable/home"
    android:title="@string/title_home"
    />

<item
    android:id="@+id/navigation_search"
    android:icon="@drawable/search"
    android:title="@string/title_dashboard" />

<item
    android:id="@+id/nav_add_post"
    android:icon="@drawable/add"
    android:title="@string/title_notifications" />

<item
    android:id="@+id/navigation_notifications"
    android:icon="@drawable/heart"
    android:title="@string/title_notifications" />

<item
    android:id="@+id/nav_profile"
    android:icon="@drawable/profile_icon"
    android:title="@string/title_notifications" />

</menu>

这是我跑步时的样子。

enter image description here

我已经提到了该帖子:Bottom Navigation View With Left Righ Space Issue,但没有帮助我解决了这个问题,我还尝试了app:itemBackground =“ @ android:color / holo_green_dark”没有解决我的间距问题。

android android-constraintlayout android-styles bottomnavigationview
1个回答
0
投票

如果不需要它,可以将其删除,并且可以正常工作;如果需要,请执行以下操作

© www.soinside.com 2019 - 2024. All rights reserved.