Change Chip Widget style programmatically not working – Android

You can’t use the constructor val chip = Chip(context, null, R.style.CustomChipChoice) because the 3rd parameter isn’t the style but the attribute in the theme as R.attr.chipStyle. The Chip hasn’t a constructor with 4 parameters as other components because it extends AppCompatCheckbox which does not support a 4 parameter constructor. However you can use something different. … Read more

Android how to center align chips in chipgroup?

I tried using Chip inside Flexbox and it worked like this. <com.google.android.flexbox.FlexboxLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center” android:orientation=”horizontal” app:flexWrap=”wrap” app:justifyContent=”center”> … </com.google.android.flexbox.FlexboxLayout> There should be better ways for achieving this but this will work there I guess. Update (2021): I removed flexbox dependency due to stability and lack of updates from Google and am achieving the same … Read more

Set com.google.android.material.chip.Chip selected color

Just set an attribute app:chipBackgroundColor and pass a color state list to it: <android.support.design.chip.Chip android:id=”@+id/test” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:checkable=”true” android:clickable=”true” android:focusable=”true” app:chipBackgroundColor=”@color/bg_chip_state_list” app:chipText=”Test” /> bg_chip_state_list looks like this: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:color=”@color/colorSecondaryLight” android:state_checked=”true” /> <item android:color=”@color/colorPrimaryDark” /> </selector> However I also had to set android:clickable to true to make this work

Android Chip Custom Height Or Padding – Chipgroup spacing

In the 1.1.0-alpha* versions extra spacing is added for the chip. After a lot of hit and trial I managed to remove that spacing using: app:chipMinTouchTargetSize=”0dp” Looking at the class file for Chip, it seems that it’s related to Android’s minimum touch target size, so consider that before changing this.

ChipGroup single selection

To prevent all chips from being deselected you can use the method setSelectionRequired: chipGroup.setSelectionRequired(true) You can also define it in the layout using the app:selectionRequired attribute: <com.google.android.material.chip.ChipGroup app:singleSelection=”true” app:selectionRequired=”true” app:checkedChip=”@id/…” ..> Note: This requires a minimum of version 1.2.0

Android material chip component crashing app. Unable to inflate xml

Update your app theme to inherit from one of these themes: Theme.MaterialComponents Theme.MaterialComponents.NoActionBar Theme.MaterialComponents.Light Theme.MaterialComponents.Light.NoActionBar Theme.MaterialComponents.Light.DarkActionBar For example: <style name=”AppTheme” parent=”Theme.MaterialComponents.Light.NoActionBar”> Note: Using a Material Components theme enables a custom view inflater Source: https://www.material.io/develop/android/docs/getting-started/