Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shapeAppearance in Material Component FloatingActionButton causes a crash

E/OpenGLRenderer: resultIndex is -1, the polygon must be invalid!
A/OpenGLRenderer: Error: Spot pair overflow!!! used 38, total 22
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 11996 (hwuiTask1)

Using shapeAppearance attribute causes a crash.

This is the FAB in XML

<com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            style="@style/Widget.MaterialComponents.FloatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/fab_margin"
            android:onClick="@{() -> callback.add(viewModel.plant)}"
            android:tint="@android:color/white"
            app:shapeAppearance="@style/ShapeAppearance.Sunflower.FAB"  <--
            app:isGone="@{viewModel.isPlanted}"
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|end"
            app:srcCompat="@drawable/ic_plus" />

Below is the style for shapeAppearance,

<style name="ShapeAppearance.Sunflower.FAB" parent="ShapeAppearance.MaterialComponents">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSizeTopLeft">0dp</item>
        <item name="cornerSizeTopRight">30dp</item>
        <item name="cornerSizeBottomRight">0dp</item>
        <item name="cornerSizeBottomLeft">30dp</item>
</style>

This solves the crash.

    <style name="ShapeAppearance.Sunflower.FAB" parent="ShapeAppearance.MaterialComponents">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSizeTopLeft">0dp</item> <--
        <item name="cornerSizeTopRight">0dp</item>
        <item name="cornerSizeBottomRight">0dp</item> --
        <item name="cornerSizeBottomLeft">0dp</item>
    </style>

I need to know the reason behind it and how to solve it while using the same corner style.

like image 957
Ashraf Patel Avatar asked Jan 01 '23 15:01

Ashraf Patel


1 Answers

Use the app:shapeAppearanceOverlay attribute:

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

And in the style (without defining the parent)

  <style name="CustomShapeOVerlay" parent="">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSizeTopLeft">0dp</item>
        <item name="cornerSizeTopRight">30dp</item>
        <item name="cornerSizeBottomRight">0dp</item>
        <item name="cornerSizeBottomLeft">30dp</item>
  </style>

enter image description here

like image 152
Gabriele Mariotti Avatar answered Jan 14 '23 08:01

Gabriele Mariotti