How to collaboration Chips from Material Design in your life?

Android Jul 7, 2019

This blog is a path in my session, Recommend Material Components for your app, in Android Bangkok 2019.

ref: for loop 1 hour

About Chips, everyone think about potato chip, chocolate chip and something like that but Chips for Android Developer is small block view to represent an input, attribute, or action in your application.

In your life, Chip is found at Google Assistance, Gmail, Google Play, and in some application.

For getting start

How to Getting Start to try Material Components in your project
I think some developer have problem for create some UI in application then Material Design help you for this.


Chips have 4 styles are action chip, filter chip, choice chip, and entry chip.

Action Chips

are default style of chips and used with action related to primary content which displayed after them.

If action chips use in Material Card, they are below divider line.

It can trigger an action or show progress and confirmation.

Filter Chips

use tags or descriptive words to filter content.

They are a good alternative to toggle buttons or checkboxes with multiple chips can be selected or unselected.


Choice Chip

allows selection of a single chip from a set of options and a good alternative to toggle buttons, radio buttons, and single select menus.

When you selecting a single choice chip automatically deselects all other chips in the set.


Entry Chip

represents a complex piece of information in a compact form. It usually contains an optional chip icon, optional close icon, and is optionally checkable.

Behaviors are transform text based on user input, can be editable util user take action, display error state, can be reordered or moved into other fields and expend to show more information.


Handling Clicks

In Material Design Document said about 3 callback function for used in Chips.

  • Call setOnClickListener to do something after click at chip for example show Snackbar after click it.
chipAction.setOnClickListener {
       "Action Chips", 
  • call setOnCheckedChangeListener to register a callback when chip is toggled for example show Snackbar text for isCheck value after click it.
chipChoice.setOnCheckedChangeListener { buttonView, isChecked ->
  • Call setOnCloseIconClickListener to do something with click close icon in entry chip for example click at close icon to hide it.
chipEntry.setOnCloseIconClickListener {
    it.visibility = View.GONE


I have some sample to use Chips for some situation in your application.

#1 Add hashtag for your menu.

What’re hashtag relate about Tonkatsu?

Tonkatsu is a Japanese food containing deep-fried pork with breadcrumbs, cabbage, Japanese rice, miso soup, and side dish. I took this dish when I have lunch with my colleagues at Katsushin which recommended by Wongnai Users’ Choice 2019.

Then hashtag about this photo are tonkatsu, Japanese food, pork, meat, lunch, bangkok, and silom.

I mockup hashtag list by chips in my Material Card with LinearLayout is parent view but have problem about cannot show all hashtag

OK, It can solve them by add horizontalScrollView to parent view then can scroll to see all hashtag.

If a designer in your team need to show all hashtag in Material Card without scroll view. How do you solve this?

This question solved by ChipGroup which contains a chip set and manage layout similar to RadioGroup.

If you get all hashtag from dynamic such as API. You should use RecyclerView to render chips.

#2 Hashtag in RecyclerView with dynamic data

If you get all hashtag from dynamic data such as API. You should use RecyclerView to render chips.

This application for the example is my blog application and redesign it to Material Design. User can get all blogs and read it in my application. Each blog has tag related to content of blog such as I write for doing Firestore Codelab from Android Bangkok last year at home, tags are Android Application, firebase, and programming.

For scroll view to see all hashtag,

You add RecyclerView in ChipGroup at your item view for use in your adapter.




and add new adapter class in HashtagChipAdapter file.

then add adapter in your RecyclerView in main adapter class.

recyclerViewHashtag.apply {

layoutManager = LinearLayoutManager(

this.adapter = HashtagChipAdapter(

For ChipGroup,

You add ChipGroup at your item view for use in your adapter layout.


and create Chip view at adapter class and add it to ChipGroup.

You don’t forget for removeAllViews at ChipGroup because they have bug with show tag with scroll up-down which view reused old view to show tags item.

if (item.labels!!.isNotEmpty()) {
    item.labels.forEach {
        val chip = Chip(containerView.context)
        chip.apply {
            layoutParams = ViewGroup.LayoutParams(
            text = it

#3 ChipGroup Selected

Last example for chip. If you select something in your app, you think of RadioButton, Checkbox, and something like that. Chip can do similar to select one thing and multiple thing in the list.

This example is make your burger, you can choose 1 meat with Choice Chips and many topping in your burger with Filter Chips.

For choose your meat with Choice Chips, add 1 ChipGroup which set singleSelection is true.


Call setOnCheckedChangeListener for get Chips id fromChipGroup to get text of meat.

chipGroupMeat.setOnCheckedChangeListener { chipGroup, id ->
    if (chipGroup.findViewById<Chip>(id) != null) {
        val meat = chipGroup.findViewById<Chip>(id).text
        Snackbar.make(rootview, meat, Snackbar.LENGTH_SHORT).show()

For Filter Chips to choose your topping, call setOnCheckChangeListener in each Chip which is a child of ChipGroups to get text for item selected.

for (i in 0 until chipGroupTopping.childCount) {
    val chip = chipGroupTopping.getChildAt(i) as Chip
    chip.setOnCheckedChangeListener { buttonView, isChecked ->
        if (isChecked) {
            Snackbar.make(rootview, chip.text, Snackbar.LENGTH_SHORT).show()

Final result in this example is get your meat and topping in your burger then you create global variable for meat and topping.

For topping, you create arrayList global variable and add it when checked and remove when unchecked.

for (i in 0 until chipGroupTopping.childCount) {
    val chip = chipGroupTopping.getChildAt(i) as Chip
    chip.setOnCheckedChangeListener { buttonView, isChecked ->
        if (isChecked) {
        } else {
        Snackbar.make(rootview, toppingList.toString(), Snackbar.LENGTH_SHORT).show()

Finally setOnClickListener in your button to get meat and topping to show in next fragment.


Chips - Material Components for Android
Create beautiful apps with modular and customizable UI components
Chips spec.
Modular and customizable Material Design UI components for Android - material-components/material-components-android
How to get selected chips from a chipgroup? · Issue #197 · material-components/material-components-android
I have a chip group for post tags. The chip group contains chips for tags, example: &quot;Announcement&quot;, &quot;Meeting&quot;, &quot;Question&quot;. The problem is I can&#39;t find a way to get...
android kotlin - ChipGroup multi selection example
MainActivity.kt package com.cfsuman.jetpack import android.content.Context import import a...

Follow my page and stay up-to-date.

อย่าลืมกด like กด share บทความกันด้วยนะคะ :)

Posted by MikkiPastel on Sunday, December 10, 2017


Minseo Chayabanjonglerd

I am a full-time Android Developer and part-time contributor with developer community and web3 world, who believe people have hard skills and soft skills to up-skill to da moon.