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

真机运行报错Error inflating class FloatingActionButton求排查

问题排查与解决方案
  • 检查自定义属性配置

    1. 确认attrs.xml中colorAccent1的定义格式正确:
      <attr name="colorAccent1" format="color"/>
      
    2. 确保当前应用主题(Theme.MaterialComponents.DayNight.DarkActionBar)中已为该属性赋值,比如在styles.xml中添加:
      <item name="colorAccent1">@color/your_target_color</item>
      
      真机可能因主题属性未正确继承,导致无法解析该自定义颜色值。
  • 统一Material Components依赖版本

    1. 打开Module级build.gradle,检查Material依赖版本,建议使用稳定兼容版,例如:
      implementation 'com.google.android.material:material:1.9.0'
      
    2. 执行gradlew dependencies命令检查依赖树,避免存在多版本Material/Support库冲突,冲突可能导致真机上组件初始化失败。
  • 修正FloatingActionButton布局写法

    1. 确保布局中使用完整且正确的类名:com.google.android.material.floatingactionbutton.FloatingActionButton,避免拼写错误。
    2. 将android:backgroundTint替换为app:backgroundTint,Material组件的属性通常使用app命名空间,同时确保布局根节点已声明:
      xmlns:app="http://schemas.android.com/apk/res-auto"
      
      部分真机对android:命名空间下的Material属性支持存在兼容问题。
  • 确认Activity主题应用

    1. 检查AndroidManifest.xml中TripActivity的android:theme属性,确保未单独设置非Material主题,导致全局主题被覆盖。
    2. 可尝试在FloatingActionButton标签内强制指定主题:
      android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar"
      
  • 清理缓存重新编译

    1. 执行gradlew clean清理项目编译缓存,重新构建安装包。
    2. 在真机上清除应用的缓存与数据后,重新安装测试,避免旧资源缓存引发的异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 11:40:43