如何更改扩展浮动操作按钮的形状?

QTh*_*son 6 android android-layout android-button floating-action-button material-components-android

我正在尝试将我的操作按钮的形状从这个默认形状更改为矩形。这是我的 xml:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:cornerRadius="90dp"
        android:text="@string/create_player_text"
        android:fontFamily="@font/proximanova_semibold"
        app:layout_constraintHorizontal_bias="0.99"
        app:layout_constraintVertical_bias="0.01"/>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Gab*_*tti 10

如果你想改变你的形状,ExtendedFloatingActionButton你可以shapeAppearanceOverlay在布局中使用该属性:

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlayExtended"
        ../>
Run Code Online (Sandbox Code Playgroud)

和:

  <style name="ShapeAppearanceOverlayExtended" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">0dp</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

如果您想要拐角半径,只需更改<item name="cornerSize">0dp</item>.

在此处输入图片说明