You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Android布局中chipText属性未找到的AAPT编译报错

报错修复方案

问题原因

你使用的app:chipText属性已在Material Components 1.1.0及后续版本中被官方移除,当前Chip组件的文本内容需要通过原生android:text属性设置。

修复步骤

  1. 替换所有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>
  1. 额外检查项(避免后续出现其他兼容问题)
  • 确认布局根节点已经添加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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 11:27:01