小编use*_*977的帖子

Jetpack Compose 预览未显示

我似乎在 compose 中使用 Preview 时遇到问题,当我使用 @preview 注释 compose 方法时,布局面板没有出现。我假设我缺少一个依赖项,但我已经从这里复制并粘贴了代码https://developer.android.com/jetpack/compose/setup。有什么建议?(尝试了通常的清除缓存,重新打开项目等):)

buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.0.0-alpha10'
        kotlinCompilerVersion '1.4.21'
    }
}

dependencies {
    implementation 'androidx.compose.ui:ui:1.0.0-alpha10'
    // Tooling support (Previews, etc.)
    implementation 'androidx.compose.ui:ui-tooling:1.0.0-alpha10'
    // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
    implementation 'androidx.compose.foundation:foundation:1.0.0-alpha10'
    // Material Design
    implementation 'androidx.compose.material:material:1.0.0-alpha10'
    // Material design icons
    implementation 'androidx.compose.material:material-icons-core:1.0.0-alpha10'
    implementation 'androidx.compose.material:material-icons-extended:1.0.0-alpha10'
    // Integration with observables
    implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-alpha10'
    implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha10'

    // UI Tests
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.0.0-alpha10'

    implementation 'com.google.android.material:material:1.2.1'
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试使用预览(在 AS 中它说从未使用过函数“DefaultPreview”)

import …
Run Code Online (Sandbox Code Playgroud)

android android-jetpack-compose

3
推荐指数
5
解决办法
3032
查看次数

标签 统计

android ×1

android-jetpack-compose ×1