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

Android Studio引用自定义Style报语法错误但项目可正常构建

Fixing "extraneous input" Error When Using Styles from themes.xml in Android Studio

If your custom styles work fine in the app but Android Studio throws false "extraneous input" errors and fails to track their references, try these solutions:

  • Move styles to styles.xml
    Google’s official documentation still recommends storing individual view styles in styles.xml, while themes.xml is intended for app-wide themes that define default styles for components. Placing your styles in the correct file aligns with the IDE’s expectations and should eliminate parsing errors.

  • Invalidate caches and restart Android Studio
    Corrupted IDE cache is a common cause of false positive errors. Navigate to File > Invalidate Caches... > Invalidate and Restart to clear stale data—this often fixes reference tracking issues as well.

  • Verify syntax in themes.xml
    Even if the project builds successfully, subtle XML syntax issues (like missing closing tags, malformed attributes, or mixing theme and style definitions) can confuse the IDE’s lint checker. Double-check your themes.xml file for any such mistakes.

  • Update Android Studio to the latest version
    Older versions of Android Studio may have bugs with recognizing styles stored in themes.xml. Updating to the latest stable release can resolve compatibility problems with the XML structure.

  • Adjust IDE inspection settings
    If the error persists, check if an overly strict XML inspection is triggering the false alert. Go to File > Settings > Editor > Inspections > XML, look for inspections related to style or theme validation, and temporarily disable the one causing the "extraneous input" error.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 17:52:42