How to use Chips component from android support library?

人走茶凉 提交于 2019-12-06 00:16:09

问题


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.


回答1:


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




回答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



来源:https://stackoverflow.com/questions/49076430/how-to-use-chips-component-from-android-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!