Search code examples
androidmaterial-designandroid-support-libraryandroiddesignsupportandroid-chips

unable to find 'app:closeIconVisible' of material chips


I am trying to use material components via support library. I get the following error when I use chip attributes that begins with "app:....". I haven't preferred to migrate to androidx since it is not stable yet. Should I download android studio 3.2 and migrate to androidx ? Could you give me some advice, please? Thanks for your help in advance.

error: attribute 'com.tarifis.tarifis:closeIconVisible' not found.

 <android.support.design.chip.Chip
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="some text"
        app:closeIconVisible="visible"
        app:closeIcon="@drawable/ic_close_black_24dp"
        />

Here is gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.tarifis.tarifis"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        repositories {
            maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
        }
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
    implementation 'com.koushikdutta.ion:ion:2.1.6'
    implementation 'com.android.support:support-v4:28.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support:design:28.0.0-alpha3'
    //implementation 'com.google.android.material:material:1.0.0-rc01'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
}

Solution

  • Fortunately, the source is open. Below is the snippet from the source that shows which attributes are available with the version of library that I am using. Since the library version that you are using is different from mine, I would suggest to find out for yourself in studio itself.

    In order to find out, just Ctrl click on the com.google.android.material.chip.ChipGroup in the xml and follow through to the com.google.material.android.chip.ChipDrawable class' loadFromAttributes() method.

    Here is a snippet for your quick reference:

    private void loadFromAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        TypedArray a = ThemeEnforcement.obtainStyledAttributes(this.context, attrs, styleable.ChipDrawable, defStyleAttr, defStyleRes);
        this.setChipBackgroundColor(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_chipBackgroundColor));
        this.setChipMinHeight(a.getDimension(styleable.ChipDrawable_chipMinHeight, 0.0F));
        this.setChipCornerRadius(a.getDimension(styleable.ChipDrawable_chipCornerRadius, 0.0F));
        this.setChipStrokeColor(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_chipStrokeColor));
        this.setChipStrokeWidth(a.getDimension(styleable.ChipDrawable_chipStrokeWidth, 0.0F));
        this.setRippleColor(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_rippleColor));
        this.setChipText(a.getText(styleable.ChipDrawable_chipText));
        this.setTextAppearance(MaterialResources.getTextAppearance(this.context, a, styleable.ChipDrawable_android_textAppearance));
        this.setChipIconEnabled(a.getBoolean(styleable.ChipDrawable_chipIconEnabled, false));
        this.setChipIcon(MaterialResources.getDrawable(this.context, a, styleable.ChipDrawable_chipIcon));
        this.setChipIconSize(a.getDimension(styleable.ChipDrawable_chipIconSize, 0.0F));
        this.setCloseIconEnabled(a.getBoolean(styleable.**ChipDrawable_closeIconEnabled**, false));
        this.setCloseIcon(MaterialResources.getDrawable(this.context, a, styleable.ChipDrawable_closeIcon));
        this.setCloseIconTint(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_closeIconTint));
        this.setCloseIconSize(a.getDimension(styleable.ChipDrawable_closeIconSize, 0.0F));
        this.setCheckable(a.getBoolean(styleable.ChipDrawable_android_checkable, false));
        this.setCheckedIconEnabled(a.getBoolean(styleable.ChipDrawable_checkedIconEnabled, false));
        this.setCheckedIcon(MaterialResources.getDrawable(this.context, a, styleable.ChipDrawable_checkedIcon));
        this.setShowMotionSpec(MotionSpec.createFromAttribute(this.context, a, styleable.ChipDrawable_showMotionSpec));
        this.setHideMotionSpec(MotionSpec.createFromAttribute(this.context, a, styleable.ChipDrawable_hideMotionSpec));
        this.setChipStartPadding(a.getDimension(styleable.ChipDrawable_chipStartPadding, 0.0F));
        this.setIconStartPadding(a.getDimension(styleable.ChipDrawable_iconStartPadding, 0.0F));
        this.setIconEndPadding(a.getDimension(styleable.ChipDrawable_iconEndPadding, 0.0F));
        this.setTextStartPadding(a.getDimension(styleable.ChipDrawable_textStartPadding, 0.0F));
        this.setTextEndPadding(a.getDimension(styleable.ChipDrawable_textEndPadding, 0.0F));
        this.setCloseIconStartPadding(a.getDimension(styleable.ChipDrawable_closeIconStartPadding, 0.0F));
        this.setCloseIconEndPadding(a.getDimension(styleable.ChipDrawable_closeIconEndPadding, 0.0F));
        this.setChipEndPadding(a.getDimension(styleable.ChipDrawable_chipEndPadding, 0.0F));
        a.recycle();
    }
    

    This library does not have app:closeIconVisible="visible" attribute as can be seen from code. Seems like your version does not too. Consider using app:closeIconEnabled="false" to hide and just setting the drawable(as you already are) to show. Although I would recommend to move to the latest version as permitted by you codebase because these libraries are very frequently updated in alpha versions.

    Happy Coding!