代码之家  ›  专栏  ›  技术社区  ›  kelalaka

Android BottomAppBar水平分布按钮

  •  0
  • kelalaka  · 技术社区  · 7 年前

    浮动操作按钮。添加按钮后,按钮将向右或向左对齐。

    enter image description here

    • 我想水平分布动作图标。我在Android开发者中找不到解决方案 reference . 如何才能做到这一点?
    1 回复  |  直到 7 年前
        1
  •  5
  •   AskNilesh    7 年前

    笔记

    如果你想删除 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

        2
  •  1
  •   Burkely91    7 年前

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

    最后一步是在图标/图像视图上添加填充/边距,您应该拥有一个漂亮的、甚至水平分布的四个图标。我认为公认的答案并没有达到这一点。