8

我已经阅读了官方网站上的文档。但是我无法按照文档在我的项目中实现芯片。Android Studio 无法找到和导入Chip类以及Chip视图。

我还注意到在谷歌开发者网站上没有芯片类的参考。

还有一些类似的问题。但所有答案都指向使用第三方库。但我正在尝试使用来自 android 支持库的 Chips 组件。

4

2 回答 2

6

该功能包含在支持库版本28.0.0-alpha1中。
要使用该功能:

在应用程序 gradle 文件中:

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'
}

在布局文件中:

<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"/>

指南:https ://material.io/guidelines/components/chips.html

于 2018-04-17T08:48:30.517 回答
2

如果您使用的是材质库

您可以使用材料芯片com.google.android.material.chip.Chipimplementation 'com.google.android.material:material:1.0.0'添加到 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"

参考

于 2019-03-02T09:36:09.150 回答