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_
相关产品推荐
相关产品推荐

