简体   繁体   English

Android studio canary 不预览 jetpack compose

[英]Android studio canary doesn't preview jetpack compose

so after jetpack compose beta was released, I updated my Android Studio Canary to the latest version, but I can't preview my app, even when I annotate my code with @Preview, there is no button called show preview or show code, they just disappeared.所以在发布了jetpack compose beta后,我将我的Android Studio Canary更新到了最新版本,但是我无法预览我的应用程序,即使我用@Preview注释我的代码,也没有称为显示预览或显示代码的按钮,他们刚刚消失了。 在此处输入图像描述

Your UI code needs to be inside a compose fuction.您的 UI 代码需要在 compose 函数中。

@Composable
fun Greeting(name: String) {
    Text (text = "Hello $name!")
}

The composable function must not take any parameters.可组合的 function 不能带任何参数。 For this reason, you can't preview the Greeting() function directly.因此,您无法直接预览 Greeting() function。 Instead, make a second function named PreviewGreeting(), which calls Greeting() with an appropriate parameter.相反,创建第二个名为 PreviewGreeting() 的 function,它使用适当的参数调用 Greeting()。 Add the @Preview annotation before @Composable.在@Composable 之前添加@Preview 注解。

@Preview
@Composable
fun PreviewGreeting() {
    Greeting("Android")
}
  

after 1 day I realized that I had to download Android Studio Canary from the website, and all thing worked just fine with the new compose beta. 1 天后,我意识到我必须从网站下载 Android Studio Canary,并且在新的 compose beta 中一切正常。 Download the ' Android studio Arctic Fox ' from this link从此链接下载“ Android 工作室北极狐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM