Search code examples
androidandroid-layoutmaterial-designandroid-bottomappbarbottomappbar

Android BottomAppBar Distribute Buttons horizontally


I want to use BottomAppBar without the Navigation drawer control and Floating Action Button. When The buttons are added they are justified to right or left.

enter image description here

  • I want to distribute the action icons horizontally. I couldn't find a solution around and in the Android developer reference. How is it possible to achieve this?

Solution

  • NOTE

    if you want remove Navigation drawer control just remove app:navigationIcon="@drawable/ic_drawer" from BottomAppBar

    output when your removed app:navigationIcon="@drawable/ic_drawer"

    SAMPLE CODE

    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:layout_gravity="bottom">
    
    
        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bar"
            android:layout_width="match_parent"
            android:layout_height="58dp"
            android:layout_gravity="bottom"
            android:backgroundTint="@color/colorPrimaryDark"
            app:navigationIcon="@drawable/ic_drawer">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="end"
                android:orientation="horizontal">
    
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:src="@drawable/ic_favorite" />
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:src="@drawable/ic_favorite" />
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:src="@drawable/ic_favorite" />
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:src="@drawable/ic_favorite" />
    
            </LinearLayout>
    
        </com.google.android.material.bottomappbar.BottomAppBar>
    
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    OUTPUT

    enter image description here