BottomNavigationView добавляет дополнительное пространство слева

Привет, у меня есть 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>

This is my menu:

<?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>

Вот как это выглядит, когда я бегаю.

введите здесь описание изображения

Я сослался на это сообщение: Нижнее представление навигации с проблемой левого правого пространства, но это не помогло мне решить проблему, и я также попробовал app: itemBackground = "@ android: color / holo_green_dark", который также не решил мою проблему с интервалом.


person adi    schedule 15.03.2020    source источник


Ответы (1)


Вы можете удалить Toolbar, если он вам не нужен, и он будет работать нормально, или, если он вам нужен, выполните следующие действия

<androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/home_toolbar"
        app:contentInsetRight="0dp"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"// this value which removes the space 
        app:contentInsetLeft="0dp"
        >

        <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/pop_up" />

</androidx.appcompat.widget.Toolbar>
person Mohammed Alaa    schedule 15.03.2020
comment
На панели инструментов по умолчанию оставлена ​​только вставка или все стороны? - person adi; 15.03.2020
comment
stackoverflow.com/questions/26455027/ - person Mohammed Alaa; 15.03.2020