如何使用 Material 库将 FloatingActionButton 变成正方形?

How to make FloatingActionButton a Square with the Material Library?

我正在尝试 FloatingActionButton 使用我样式中的 material 库制作一个正方形:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="mini"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_margin="16dp"/>

您可以使用 ExtendedFloatingActionButton 0dp 角

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:shapeAppearanceOverlay="@style/SquareFAB" />

在styles.xml或themes.xml中:

<style name="SquareFAB" parent="">
    <item name="cornerSize">0dp</item>
</style>

更新:

But I want it the same size as my mini fab button i.imgur.com/Qg9kzdu.png which has the attribute app:fabSize="mini"

As per documentation,FAB的mini大小为40dp;所以你可以将其调整为宽度和高度:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:layout_width="40dp"
        android:layout_height="40dp"
        app:shapeAppearanceOverlay="@style/SquareFAB" />