尝试过芯片组件
com.google.android.support:design:28.0.0-rc01
和材料
com.google.android.material:material:1.0.0-rc01
StackTrace
android.view.InflateException: Binary XML file line #72: Binary XML file line #72: Error inflating class com.google.android.material.chip.Chip at android.view.LayoutInflater.inflate(LayoutInflater.java:551) at android.view.LayoutInflater.inflate(LayoutInflater.java:429)`
布局
<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account"
app:closeIconEnabled="true" />`
答案 0 :(得分:34)
更新您的应用程序主题以继承以下主题之一:
Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
例如:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
注意:使用“材料组件”主题可以启用自定义视图充气器
来源: https://www.material.io/develop/android/docs/getting-started/
答案 1 :(得分:1)
最后获得了一种解决方案,该方法是如何使用新材料切屑动态生成切屑
Google尚未提供关于chipsInput布局或如何生成Gmail地址(如layout)的任何文档。使用ChipDrawable不会对芯片选项进行删除操作,因为无法调用setOnCloseIconClickListener。我能够使用HorizontalScrollView,ChipGroup和EditText进行操作
这是我的代码示例:
答案 2 :(得分:1)
在您现有的应用程序主题中添加以下新主题属性:
<style name="Theme.MyApp" parent="Theme.AppCompat">
<!-- Original AppCompat attributes. -->
<item name="colorPrimary">@color/my_app_primary_color</item>
<item name="colorPrimaryDark">@color/my_app_primary_dark_color</item>
<item name="colorAccent">@color/my_app_accent_color</item>
<!-- New MaterialComponents attributes. -->
<item name="colorSecondary">?attr/colorPrimary</item>
<item name="scrimBackground">@color/mtrl_scrim_color</item>
<item name="textAppearanceHeadline1">@style/TextAppearance.MaterialComponents.Headline1</item>
<item name="textAppearanceHeadline2">@style/TextAppearance.MaterialComponents.Headline2</item>
<item name="textAppearanceHeadline3">@style/TextAppearance.MaterialComponents.Headline3</item>
<item name="textAppearanceHeadline4">@style/TextAppearance.MaterialComponents.Headline4</item>
<item name="textAppearanceHeadline5">@style/TextAppearance.MaterialComponents.Headline5</item>
<item name="textAppearanceHeadline6">@style/TextAppearance.MaterialComponents.Headline6</item>
<item name="textAppearanceSubtitle1">@style/TextAppearance.MaterialComponents.Subtitle1</item>
<item name="textAppearanceSubtitle2">@style/TextAppearance.MaterialComponents.Subtitle2</item>
<item name="textAppearanceBody1">@style/TextAppearance.MaterialComponents.Body1</item>
<item name="textAppearanceBody2">@style/TextAppearance.MaterialComponents.Body2</item>
<item name="textAppearanceCaption">@style/TextAppearance.MaterialComponents.Caption</item>
<item name="textAppearanceButton">@style/TextAppearance.MaterialComponents.Button</item>
<item name="textAppearanceOverline">@style/TextAppearance.MaterialComponents.Overline</item>
</style>
来源:https://material.io/develop/android/docs/getting-started/
谢谢@ Paranoid42
答案 3 :(得分:0)
您可以像这样在xml布局中添加@ style / Theme.MaterialComponents.Light样式属性:
kivy
答案 4 :(得分:-1)
添加chip
组件,该组件包含在android支持库中。
实现'com.android.support:design:28.0.0-rc01'
<android.support.design.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
已编辑
将此添加到您的gradle文件中
implementation group: 'com.google.android.material', name: 'material', version: '1.0.0-alpha1'
xml
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipText="MATERIAL CHIP" />
输出