Android Studio使用AndroidX库时CoordinatorLayout找不到布局预览空白求助
问题解决步骤
- 依赖版本适配:你当前使用的compileSdk 31与搭配的material 1.4.0、appcompat 1.4.0版本存在和Android Studio布局渲染器的兼容缺陷,直接将build.gradle中的依赖升级为对应匹配的稳定版本即可:
dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.navigation:navigation-fragment:2.5.3' implementation 'androidx.navigation:navigation-ui:2.5.3' // 其余测试依赖保持原有配置不变即可 } - 主题配置校验:确保
res/values/themes.xml下的应用根主题父类为MaterialComponents系列主题,禁止使用AppCompat系列主题,参考配置如下:<style name="Theme.FixHelp" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <!-- 原有主题的色值、属性配置保持不变即可 --> </style> - 清理缓存重启:点击Android Studio顶部菜单栏
File → Invalidate Caches...,勾选Clear file system cache and local history后点击「Invalidate and Restart」,等待项目重启并自动完成全量编译即可。 - 偶发异常处理:如果操作后仍偶尔出现
Class not found project报错,确认无自定义drawable语法错误的前提下,直接点击布局预览面板右上角的刷新按钮即可恢复正常。
内容的提问来源于stack exchange,提问作者TheGamerPotato
相关产品推荐
相关产品推荐

