android BottomAppBar 有额外的左侧填充

标签 android layout android-bottomappbar

我正在使用 BottomAppBar在我的应用程序中,但它有一个额外的左侧填充。如何删除此填充?
我的xml代码是:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/spark_secondary_color"
        >

        <LinearLayout
            android:id="@+id/bottom_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:background="@color/white"
            android:orientation="horizontal"
            >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical">

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@android:drawable/ic_menu_search"
                    android:background="?attr/selectableItemBackground"
                    />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center">

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@android:drawable/ic_menu_send"
                    android:background="?attr/selectableItemBackground"
                    />

            </LinearLayout>

        </LinearLayout>

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


</androidx.coordinatorlayout.widget.CoordinatorLayout>

结果是:

enter image description here

最佳答案

添加 app:contentInsetStart="0dp"BottomAppBar解决了我的问题。

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetRight="0dp"
    app:contentInsetEnd="0dp"
    app:elevation="8dp"
    app:hideOnScroll="true"
    >
     ...

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

关于android BottomAppBar 有额外的左侧填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57883689/

相关文章:

android - Android Firebase实现不正确

html - 如何处理网页中不同长度的语言?

android - 如何将底部应用栏与顶部应用栏配对?

java - 如何让Android应用程序在安装时有一个包含图像的文件夹?

android - Libgdx 和 Leadbolt

Android animateLayoutChanges : can I set a listener?

android - 如何通过单击和更改按钮功能在另一个布局中加载布局?

android - 我的 BottomAppBar 覆盖了我的 RecyclerView 的最后一行

android - 如何将新 Material BottomAppBar 实现为 BottomNavigationView

java - 比多次 if (){do} 检查更优雅的代码