Cannot add icon in a Chip
Asked Answered
C

4

7

I have implemented 3 Chip within a ChipGroup in my application successfully, but I am having trouble making an icon at the left appear.

<android.support.design.chip.ChipGroup
    android:id="@+id/chip_group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="32dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/img_announcement_photo"
    app:singleLine="true"
    app:singleSelection="true">

    <android.support.design.chip.Chip
        android:id="@+id/chip_donate"
        style="@style/ChipStyle"
        android:checked="true"
        app:chipIcon="@drawable/ic_donate_black_24dp" />

    <android.support.design.chip.Chip
        android:id="@+id/chip_sell"
        style="@style/ChipStyle"
        app:chipIcon="@drawable/ic_sell_black_24dp" />

    <android.support.design.chip.Chip
        android:id="@+id/chip_trade"
        style="@style/ChipStyle"
        app:chipIcon="@drawable/ic_trade_black_24dp" />
</android.support.design.chip.ChipGroup>

But it doesn't show. I've tried programmatically as well, but no success. I am not yet using the new namespace, but the old com.android.support:design:28.0.0-alpha3 because I am also using Google Maps, and it is not yet supported by androidx.*.

Corelative answered 10/7, 2018 at 15:6 Comment(1)
What is @style/ChipStyle ?Harrison
H
15

Try adding app:chipIconVisible="true" to your chip style .

Huntley answered 29/11, 2019 at 6:20 Comment(0)
G
10

Actually since app:chipIconEnabled is deprecated it has to be app:chipIconVisible="true" now.

Gibbie answered 3/12, 2020 at 9:38 Comment(0)
P
4

If your style @style/ChipStyle contains style="@style/Widget.MaterialComponents.Chip.Choice" or style="@style/Widget.MaterialComponents.Chip.Filter", the icon will not show. I don't know what Google's reasoning is for this but I think is pretty silly.

Piecework answered 22/3, 2019 at 9:28 Comment(1)
I totally agree. But still you can make the icon visible with app:chipIconVisible="true"!Bobwhite
M
0

In my case the problem was with setting android:background instead of app:chipBackgroundColor. That was making chip icon invisible.

Musa answered 5/1 at 20:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.