BottomNavigationView добавляет дополнительное пространство слева - PullRequest
0 голосов
/ 15 марта 2020

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

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

1 Ответ

1 голос
/ 15 марта 2020

Вы можете удалить 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...