该问题可能是由于使用了过时的依赖项或混合使用了Compose UI和旧版Android UI导致的。解决方法是使用正确的Compose依赖项和更新app的构建.gradle文件。具体来说,需要使用以下依赖项:
implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
implementation 'androidx.compose.ui:ui-tooling:1.0.0-beta09'
并确保在构建.gradle文件中使用以下插件:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'androidx.navigation.safeargs.kotlin'
id 'dagger.hilt.android.plugin'
id 'kotlin-kapt'
id 'androidx.compose'
}
最后,还需要在AndroidManifest.xml文件中将PreviewActivity更改为ComposeView。例如: