【问题标题】:How to use Chips component from android support library?如何使用 android 支持库中的 Chips 组件?
【发布时间】:2018-03-02 19:56:10
【问题描述】:

我已阅读official website 上的文档。但是我无法按照文档在我的项目中实现芯片。 Android Studio 无法找到并导入 Chip 类以及 Chip 视图。

我还注意到Google Developer site 上没有 Chip 类的引用。

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

【问题讨论】:

  • 该文档不适用于 Android 支持库。该文档适用于this library
  • 那么,如何使用芯片组件呢?我需要导入一些东西吗?
  • 我没有看到他们在哪里记录了如何使用该代码,抱歉。
  • { compileSdkVersion = 'android-P' //26 targetSdkVersion = 'P' buildToolsVersion = '28.0.0-alpha1' supportLibVersion ='28.0.0-alpha1' } 然后将 ChipGroup 添加到布局 NB 中:仅适用于 Android P 模拟器

标签: android material-design android-chips


【解决方案1】:

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

【讨论】:

  • 我们可以在生产级别使用它吗?
  • 我不建议在稳定版本之前使用它(用于生产),因为稳定版本中的 api 可能会从 alpha 版本中更改。我猜稳定版很快就会上线。
【解决方案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"

refer

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    相关资源
    最近更新 更多