如何修复Android布局中chipText属性未找到的AAPT编译报错
报错修复方案
问题原因
你使用的app:chipText属性已在Material Components 1.1.0及后续版本中被官方移除,当前Chip组件的文本内容需要通过原生android:text属性设置。
修复步骤
- 替换所有Chip标签中的
app:chipText属性为android:text,修改后的布局代码参考如下:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:orientation="horizontal"> <com.google.android.material.chip.Chip android:layout_width="wrap_content" android:layout_height="wrap_content" app:chipBackgroundColor="@android:color/holo_blue_bright" android:text="Background Color" /> <com.google.android.material.chip.Chip style="@style/Widget.MaterialComponents.Chip.Choice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ripple Color" app:rippleColor="@android:color/holo_orange_dark" /> <com.google.android.material.chip.Chip android:layout_width="wrap_content" android:layout_height="wrap_content" app:chipIcon="@mipmap/ic_launcher" android:text="Chip icon" /> </LinearLayout>
- 额外检查项(避免后续出现其他兼容问题)
- 确认布局根节点已经添加Material组件所需命名空间:
xmlns:app="http://schemas.android.com/apk/res-auto" - 确认Module级build.gradle中已引入稳定版Material Components依赖,示例:
implementation 'com.google.android.material:material:1.8.0' - 确认App的主题继承自
Theme.MaterialComponents系列,而非旧版AppCompat主题。
内容的提问来源于stack exchange,提问作者jay raman
相关产品推荐
相关产品推荐

