Как настроить форму кнопки с плавающим действием? - PullRequest
3 голосов
/ 24 января 2020

Я пытаюсь создать пользовательский FAB с пользовательской формой. Я попытался установить android: background вместе со свойством shapeAppearanceOverlay и shapeAppearance, но все равно не повезло.

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/edit_score_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:shapeAppearance="@drawable/edit_score_fab"
            app:shapeAppearanceOverlay="@drawable/edit_score_fab"
            android:background="@drawable/edit_score_fab"/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <size
        android:height="5dp"
        android:width="10dp"/>
    <corners android:bottomLeftRadius="4dp" />
    <solid android:color="@color/color_primary"/>
</shape>

Мой результат

enter image description here

Что я хочу

enter image description here

1 Ответ

1 голос
/ 28 января 2020

Вы можете использовать ExtendedFloatingActionButton с пользовательским видом фигуры.
Что-то вроде:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
    app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlayExtended"
    ../>

с:

  <style name="ShapeAppearanceOverlayExtended" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">0dp</item>
    <item name="cornerSizeTopLeft">50%</item>
  </style>

enter image description here

...