0
0

More than 3 years have passed since last update.

BottomAppBarの左に余白が出来てしまう

Posted at

BottomAppBarの中にBottomNavigationViewを入れると「左に余白」が出来てしまうときの対処法です。

▼左に余白ができている

BottomAppBarapp:contentInsetStartを設定する

BottomAppBarapp:contentInsetStart="0dp"を設定します。

ちなみに、app:contentInsetLeft="0dp"だとダメでした。

activity_main.xml
<com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="bottom"
        app:contentInsetStart="0dp">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/purple_500"
            app:itemIconTint="@color/white"
            app:itemTextColor="@color/white"
            app:menu="@menu/menu_navigation" />

</com.google.android.material.bottomappbar.BottomAppBar>

▼左の余白がなくなっている

まとめ

全体のコードを載せておきます。

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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.bottomappbar.BottomAppBar
        android:id="@+id/bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="bottom"
        app:contentInsetStart="0dp">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/purple_500"
            app:itemIconTint="@color/white"
            app:itemTextColor="@color/white"
            app:menu="@menu/menu_navigation" />

    </com.google.android.material.bottomappbar.BottomAppBar>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
res/menu/menu_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/item_01"
        android:icon="@drawable/ic_launcher_foreground"
        android:title="item-01" />

    <item
        android:id="@+id/item_02"
        android:icon="@drawable/ic_launcher_foreground"
        android:title="item-02" />

    <item
        android:id="@+id/item_03"
        android:icon="@drawable/ic_launcher_foreground"
        android:title="item-03" />

    <item
        android:id="@+id/item_04"
        android:icon="@drawable/ic_launcher_foreground"
        android:title="item-04" />

    <item
        android:id="@+id/item_05"
        android:icon="@drawable/ic_launcher_foreground"
        android:title="item-05" />
</menu>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0