如何使用Android支持库中的Chips组件?

9
我已经阅读了官方网站上关于Chip的文档。但是我按照文档的指引在我的项目中无法实现Chip。Android Studio找不到和导入Chip类以及Chip视图。
我也注意到在Google开发者网站上没有Chip类的参考资料。
有一些类似的问题,但所有答案都指向使用第三方库。但我正在尝试使用来自android支持库的Chips组件。

那份文档不是针对 Android Support Library 的。那份文档是针对 这个库的。 - CommonsWare
那么,我如何使用芯片组件?我需要导入什么吗? - zoha131
抱歉,我没有看到他们记录如何使用那段代码的地方。 - CommonsWare
{ compileSdkVersion = 'android-P' //26 targetSdkVersion = 'P' buildToolsVersion = '28.0.0-alpha1' supportLibVersion ='28.0.0-alpha1' } 然后将ChipGroup添加到布局中 注意:仅适用于Android P模拟器 - Marc
2个回答

7
该功能包含在支持库版本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

1
https://medium.com/google-developer-experts/exploring-the-v28-android-design-support-library-2c96c6031ae8 - Pramod Garg
我们可以在生产环境中使用这个吗? - Ramiz Ansari
在稳定版本发布之前,我不建议在生产中使用它,因为稳定版本的API可能与alpha版本不同。我猜稳定版本很快就会发布。 - Pramod Garg

2
如果您正在使用Material库,您可以使用Material Chip 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"

refer


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接