lidkxx
lidkxx

Reputation: 2841

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? :/

Upvotes: 12

Views: 10976

Answers (3)

live-love
live-love

Reputation: 52424

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();
            ...
}}

Upvotes: 5

Hassan Ashraf
Hassan Ashraf

Reputation: 11

Change your app theme from Theme.AppCompat. to Theme.MaterialComponents.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

to

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="chipIconTint">@color/colorAccent</item>
</style>

Upvotes: 0

lidkxx
lidkxx

Reputation: 2841

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>

Upvotes: 22

Related Questions