Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not show Checked Icon On Material Components Chip Android

Edit: I managed to make it work by setting the below attirbutes in styles.xml like so:

  <android.support.design.chip.Chip
                    android:id="@+id/chipFollowing"
                    style="@style/ChipCustomStyle" ...>

styles.xml

<style name="ChipCustomStyle" parent="Widget.MaterialComponents.Chip.Action">
    <item name="checkedIconEnabled">false</item>
    <item name="checkedIcon">@null</item>
</style>

Leaving it here in case anyone runs into the same WTF :)


Original question:

I don't want to show checked icon on my Chip. I tried setting

        app:checkedIcon="@null"
        app:checkedIconVisible="false"

both in Chip and ChipGroup element. It won't even compile :/

When I set it on Chip element, I am getting: error: attribute 'com.companyname.projectname:checkedIconVisible' not found.

Here is my Chip XML:

            <android.support.design.chip.Chip
                android:id="@+id/chipFollowing"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checkable="true"
                android:clickable="true"
                android:focusable="true"
                android:textAppearance="@style/ChipFilledUncheckedText"
                app:checkedIcon="@null"
                app:checkedIconVisible="false"
                app:chipBackgroundColor="@color/bg_chip_state_list"
                app:chipText="@string/chip_following" />

I am using Material Components from the 28 Support Library version. Am I missing something obvious? :/

like image 253
lidkxx Avatar asked Aug 08 '18 13:08

lidkxx


2 Answers

I managed to make it work by setting the below attirbutes in styles.xml like so:

  <android.support.design.chip.Chip
                    android:id="@+id/chipFollowing"
                    style="@style/ChipCustomStyle" ...>

styles.xml

<style name="ChipCustomStyle" parent="Widget.MaterialComponents.Chip.Action">
    <item name="checkedIconEnabled">false</item>
    <item name="checkedIcon">@null</item>
</style>
like image 152
lidkxx Avatar answered Nov 15 '22 21:11

lidkxx


You can just use setCheckable and setCheckedIconVisible

Example:

for (int i = 0; i < array.size(); i++) {
KeyValueSelectedEntity letter = array.get(i);
if (getContext() != null) {
    Chip chip = new Chip(getContext());
    chip.setId(letter.getId());
    chip.setText(letter.getName());
    chip.setTag(i);
    chip.setCheckable(true);
    chip.setCheckedIconVisible(false);
    chip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean selected) {
            Log.d(TAG, "onCheckedChanged");
            int tag = (int) compoundButton.getTag();
            ...
}}
like image 23
live-love Avatar answered Nov 15 '22 21:11

live-love