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

Android应用运行报错:无法确定?attr/colorSurface标签类型

解决Android应用运行时“Can't determine type for tag '?attr/colorSurface'”错误

Can't determine type for tag '?attr/colorSurface'

错误截图

  • 确保应用主题继承Material Components主题,比如在styles.xml中设置:

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- 其他主题配置 -->
    </style>
    

    ?attr/colorSurface是Material主题专属属性,AppCompat主题不支持该引用。

  • 检查属性引用场景:不要在不支持主题属性的资源中直接使用?attr/colorSurface,比如drawable的根节点。如果需要在drawable内使用,可通过android:theme指定Material主题上下文,或替换为具体颜色值@color/surface_color。

  • 确认Material Components依赖已引入:在Module级别的build.gradle中添加依赖并同步:

    implementation 'com.google.android.material:material:1.9.0'
    
  • 清理重建项目:执行Build > Clean Project后再Build > Rebuild Project,清除资源缓存异常。

内容的提问来源于stack exchange,提问作者studentboi_

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 08:40:31