裁剪FloatingActionButton

时间:2019-12-24 20:25:34

标签: android material-design

我无法使用正确的按钮。如果我们为CoordinatorLayout设置android:layout_height = "90dp",那么一切都会变好,但是我希望它没有硬值。我可以这样做吗?

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

        <androidx.viewpager.widget.ViewPager
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            />

    <androidx.coordinatorlayout.widget.CoordinatorLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <com.google.android.material.floatingactionbutton.FloatingActionButton

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_add_24px"
            app:layout_anchor="@id/bottom_app_bar"
            app:tint="@null" />

        <com.google.android.material.bottomappbar.BottomAppBar
            style="@style/Widget.MaterialComponents.BottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:fabAlignmentMode="center"
            app:menu="@menu/days_bottomappbar_menu" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:2)

在app / build.gradle中,您导入:

implementation 'com.google.android.material:material:1.0.0'

在xml中

<androidx.coordinatorlayout.widget.CoordinatorLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottom_app_bar"
        style="@style/Widget.MaterialComponents.BottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:fabAlignmentMode="center"
        android:layout_gravity="bottom"/>
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_add_24px"
        app:layout_anchor="@id/bottom_app_bar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>