9

I have read the documentation on the official website. But I was unable to implement Chip in my project following the documentation. Android Studio can't find and import Chip class as well as Chip view.

I have also noticed that on Google Developer site there is no reference for Chip class.

There are some similar questions. But all answers point to use a third-party library. But I am trying to use Chips component from android support library.

Edric
  • 24,639
  • 13
  • 81
  • 91
zoha131
  • 1,758
  • 2
  • 16
  • 18
  • That documentation is not for the Android Support Library. That documentation is for [this library](https://github.com/material-components/material-components-android). – CommonsWare Mar 02 '18 at 20:01
  • Then, how can I use Chips Component? Do I need to import something? – zoha131 Mar 02 '18 at 20:08
  • I do not see where they have documented how to use that code, sorry. – CommonsWare Mar 02 '18 at 20:10
  • { compileSdkVersion = 'android-P' //26 targetSdkVersion = 'P' buildToolsVersion = '28.0.0-alpha1' supportLibVersion ='28.0.0-alpha1' } then add ChipGroup into layout NB: only works on Android P emulator – Marc Apr 08 '18 at 22:28

2 Answers2

7

The feature is included in support library version 28.0.0-alpha1.
To use the feature:

In app gradle file:

android {
compileSdkVersion 'android-P'
}

dependencies {
  implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
  
  implementation 'com.android.support:design:28.0.0-alpha1'
  // OR
  implementation 'com.android.support:design-chip:28.0.0-alpha1'
}

In Layout file:

<android.support.design.chip.Chip
    style="@style/Widget.MaterialComponents.Chip.Entry"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:chipIcon="@drawable/ic_arrow_drop_down_black_24dp"
    app:chipText="hello"/>

Guidelines : https://material.io/guidelines/components/chips.html

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Pramod Garg
  • 2,183
  • 1
  • 24
  • 29
2

If you are using the material library

You can use material chip com.google.android.material.chip.Chip and implementation 'com.google.android.material:material:1.0.0' add in build.gradle

Filter style="@style/Widget.MaterialComponents.Chip.Filter"

Choice Chips style="@style/Widget.MaterialComponents.Chip.Choice"

Entry input: style="@style/Widget.MaterialComponents.Chip.Entry"

refer

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Arul Pandian
  • 1,685
  • 15
  • 20