Android BottomAppBar水平分布按钮

时间:2019-02-06 12:11:31

标签: android android-layout material-design android-bottomappbar bottomappbar

我想在没有导航抽屉控件的情况下使用BottomAppBar,并且 浮动操作按钮。添加按钮后,它们左右对齐。

enter image description here

  • 我想水平分布动作图标。我在Android开发人员reference周围和周围找不到解决方案。如何做到这一点?

2 个答案:

答案 0 :(得分:2)

注意

如果要删除Navigation drawer control,只需从 app:navigationIcon="@drawable/ic_drawer"

中删除 BottomAppBar

output when your removed 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>

输出

enter image description here

答案 1 :(得分:0)

通过删除以下行来删除通知图标:

    app:navigationIcon="@drawable/ic_drawer"

来自

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

然后您可以在bottomappbar中添加左右填充:

<android.support.design.bottomappbar.BottomAppBar
        android:theme="@style/Widget.MaterialComponents.BottomAppBar"
        android:id="@+id/bottom_app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:paddingStart="40dp"
        android:paddingLeft="40dp"
        android:paddingEnd="40dp"
        android:paddingRight="40dp"
        app:backgroundTint="@color/colorPrimary"
        app:fabAlignmentMode="center"/>

这会将四个图标居中在bottomAppBar的中间。

最后一步是在图标/图像视图上添加填充/边距,您应该拥有一个水平甚至均匀分布的四个图标。我认为接受的答案不能完全达到目的。

相关问题