Material toggle button problem on Android API 21

  android, material-design

I use material toggle button group like this

    <com.google.android.material.button.MaterialButtonToggleGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:singleSelection="true">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btn_topso"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:background="@drawable/about"
            android:layout_height="wrap_content"
            android:text="@string/topo" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btn_averages"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/average" />

    </com.google.android.material.button.MaterialButtonToggleGroup>

But when run the application, crash with this error:

 java.lang.IllegalStateException: Attempted to get ShapeAppearanceModel from a MaterialButton which has an overwritten background.
        at com.google.android.material.button.MaterialButton.getShapeAppearanceModel(MaterialButton.java:1169)
        at com.google.android.material.button.MaterialButtonToggleGroup.addView(MaterialButtonToggleGroup.java:244)
        at android.view.ViewGroup.addView(ViewGroup.java:3709)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)

I can’t fix it!, how can I solve this issue?

Material version: ‘1.3.0-alpha03’

Style:

    <style name="MaterialAppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primaryDark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:buttonStyle">@style/ButtonStyle</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="floatingActionButtonStyle">@style/FloatingButtonStyle</item>
</style>

Source: Android Questions

LEAVE A COMMENT