在我所有的Android应用程序中,我都实现了Material Design Components(MDC)依赖关系,AndroidX并且一切正常,直到将Android Studio更新到3.4稳定版本为止。该应用程序可以在模拟器和真实手机中编译并完美运行,但是Android Studio 的XML Layout Previewer 不会呈现任何MDC,并且Preview页面会冻结。
我已经尝试了很多事情,但没有一个可以解决我的问题:
targetSdkVersion和更改compileSdkVersions为28Theme.MaterialComponents变体此XML布局预览器问题仅在其中至少包含1个MDC的布局中出现。如果没有这些组件,则一切正常。
我的styles.xml文件如下所示:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorGroupPrimary">@color/colorPrimary</item>
<item name="colorGroupPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorGroupAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/montserrat</item>
<item name="android:windowBackground">@drawable/splash_bg</item
</style>
Run Code Online (Sandbox Code Playgroud)
即使我将其扩展AppTheme为Theme.MaterialComponents.Light.NoActionBar也不起作用。
我的build.gradle文件如下所示:
android {
compileSdkVersion 28
defaultConfig …Run Code Online (Sandbox Code Playgroud)