Connect with us

Code

MaterialChipSetWidget – Chipsets for Android

A MaterialChipSetWidget is used to hold multiple chipsets and each chipset has multiple values.

Including in your project

Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
        mavenCentral()
    }
}

And add a dependency code to your module‘s build.gradle file.

dependencies {
    implementation 'com.github.JustinGeorgeJoseph:MaterialChipsetWidget:v1.0.1'
}

Usage

ColorPickerView in XML layout

We can use MaterialChipSetsContainer without any customized attributes.
Initally there won’t be any content you have add those contents dynamically.

    <com.justin.materialchipsetwidget.MaterialChipSetsContainer
        android:id="@+id/materialChipSetsContainer"
        android:layout_width="match_parent"
        android:scrollbars="none"
        android:layout_height="wrap_content"/>

Attribute descriptions

android:scrollbars="none" // sets whether a horizontal scrollbar is required or not.

Initalize MaterialChipsetWidget with chips

Create a list of data that should be shown in the widget

    private fun createDataSet(): List<List<String>> {
        val arrayTime = arrayListOf("Recent", "2000s", "90s", "Old")
        val arrayPurchaseMode = arrayListOf("Paid", "Rent")
        val arrayGenre = arrayListOf("Action", "Comedy", "Sci-Fi", "Science", "Drama")
        val arrayRating = arrayListOf("Award-winning", "Highly rated")
        return arrayListOf(arrayPurchaseMode, arrayTime, arrayGenre, arrayRating)
    }

Initialize the widget with colors and dataset

findViewById<MaterialChipSetsContainer>(R.id.materialChipSetsContainer).apply {

            chipSetSolidColorUnselected = ContextCompat.getColor(context, android.R.color.black)
            chipSetSolidColorSelected = ContextCompat.getColor(context, R.color.green)
            chipSetStrokeWidth = Utils.convertDpToPx(this@MainActivity, 3)
            chipSetStrokeColorUnselected =
                ColorStateList.valueOf(ContextCompat.getColor(context, R.color.green))
            chipSetStrokeColorSelected =
                ColorStateList.valueOf(ContextCompat.getColor(context, R.color.green))

            chipTextColorUnselected = ContextCompat.getColor(context, android.R.color.white)
            chipTextColorSelected = ContextCompat.getColor(context, android.R.color.white)
            chipTextDividerColorUnselected =
                ContextCompat.getColor(context, R.color.green)

            dataSet = createDataSet()
        }

MaterialChipsetWidgetListener

MaterialChipsetWidgetListener {

                override fun onChipSelectionChanged(
                    name: String?,
                    chipSelectionGroup: String,
                    checked: Boolean,
                ) {
                    
                }

                override fun onChipsetsResetClicked() {
                   
                }

            }

MaterialChipSetWidget on GitHub: https://github.com/JustinGeorgeJoseph/MaterialChipsetWidget 
Platform: Android 
⭐️: 15
Advertisement

Trending