Search code examples
androidstylesmaterial-components-androidandroid-chips

Android ChipDrawable width not fill his parrent


I'm trying to use ChipGroup that hold some Chips with text only. everything works fine. the problem starts when there is short text. for some reason the text doesn't fill the chip itself, and i can't fix that... enter image description here enter image description here

I'm using this layout for Chip:

<com.daytwo.core.widget.CustomChip         
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chip"
style="@style/Chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="64dp"/>

And my style is:

<style name="Chip" parent="@style/Widget.MaterialComponents.Chip.Choice">
    <item name="android:textColor">@color/black</item>
    <item name="chipBackgroundColor">@color/background</item>
    <item name="rippleColor">@color/ripple</item>
    <item name="chipStrokeWidth">2dp</item>
    <item name="chipMinHeight">50dp</item>
</style>

Solution

  • This Chip has a chipMinTouchTargetSize.This affects both the vertical and horizontal margin of a chip to ensure that it is at least 48x48dp.

    enter image description here

    You can disable it using app:ensureMinTouchTargetSize="false" in each chip of the ChipGroup.

    enter image description here