Android BottomAppBar 水平分布按钮

kel*_*aka 0 android android-layout material-design android-bottomappbar bottomappbar

我想使用没有导航抽屉控件和浮动操作按钮的 BottomAppBar。添加按钮时,它们会向右或向左对齐。

在此处输入图片说明

  • 我想水平分布动作图标。我在 Android 开发人员参考中找不到解决方案。怎么可能做到这一点?

Nil*_*hod 5

笔记

如果你想删除Navigation drawer control只是删除app:navigationIcon="@drawable/ic_drawer"从BottomAppBar

移除时的输出 app:navigationIcon="@drawable/ic_drawer"

示例代码

<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>
Run Code Online (Sandbox Code Playgroud)

输出

在此处输入图片说明