Sunday, November 15, 2020

Android Chip component

 A Chip is a component that can represent input, filter, choice or action of a user

But this required the theme to be inherited from Material theme, else it was giving this error


android.view.InflateException: Binary XML file line #142: Binary XML file line #142: Error inflating class com.google.android.material.chip.Chip


adjusting the style to below gave this error to go away


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

        <!-- Customize your theme here. -->

        <item name="colorPrimary">@color/colorPrimary</item>

        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

        <item name="colorAccent">@color/colorAccent</item>

        <item name="chipIconTint">@color/chipIconTint</item>


        <item name="android:colorButtonNormal">@drawable/button_selector</item>

        <item name="colorButtonNormal">@drawable/button_selector</item>

        <item name="android:buttonStyle">@style/FriendlyButtonStyle</item>

    </style>


<com.google.android.material.chip.ChipGroup

            android:id="@+id/chipGroup"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_centerInParent="true">


            <com.google.android.material.chip.Chip

                android:id="@+id/chip6"

                style="@style/Widget.MaterialComponents.Chip.Filter"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Fire" />


            <com.google.android.material.chip.Chip

                android:id="@+id/chip7"

                style="@style/Widget.MaterialComponents.Chip.Filter"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Water" />


            <com.google.android.material.chip.Chip

                android:id="@+id/chip8"

                style="@style/Widget.MaterialComponents.Chip.Filter"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Psychic" />

        </com.google.android.material.chip.ChipGroup>



references:

https://medium.com/material-design-in-action/chips-material-components-for-android-46001664a40f#:~:text=A%20Chip%20is%20a%20component,or%20action%20of%20a%20user.


No comments:

Post a Comment