5

I'm going through the tutorials about Jetpack which is ran in the Android Studio 4.0(Canary), please refer to the link post below.

https://developer.android.com/jetpack/compose/tutorial

Everything is ready except I can't find the preview window since I try to preview the "Composable" method.

Can someone give me an exact hint that where the preview window is?

Blundell
  • 75,855
  • 30
  • 208
  • 233
Wayne Lee
  • 53
  • 3

2 Answers2

3

Check the official site:

Beginning with Android Studio 4.0 Canary 1, Android Studio lets you preview your composable functions within the IDE, instead of needing to download the app to an Android device or emulator. The main restriction is, the composable function must not take any parameters. Add the @Preview annotation before @Composable.

Then select on the top-right the Editor and Preview toggle.

enter image description here

enter image description here

To update the preview click the Build Refresh button.

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Hi, The question was that I've followed the guide of official site and I can find nothing on the top-right of my Android Studio, I get no entrance to open the preview window. – Wayne Lee Oct 31 '19 at 07:46
  • Ok, I take the advice from @Alex H and it just works after I restart Android Studio. – Wayne Lee Oct 31 '19 at 07:52
  • Is this behaviour by design (@Preview + restart AS) ? Anyway, have anyone filed an issue at issuetracker on this ? – Roar Grønmo Oct 31 '19 at 09:55
  • 1
    @RoarGrønmo The preview works if the project can be built. If there are errors the preview doesn't work. It doesn't need a restart in my experience. – Gabriele Mariotti Oct 31 '19 at 10:26
  • 1
    As a principle, the preview should rather be showing an errormessage / lint when trying to show the preview, rather than not showing anything at all. At once the @Preview annitation is used, the preview window should be brought up. -> We may suggest this at issuetracker. – Roar Grønmo Oct 31 '19 at 10:54
  • Found this at issuetracker: https://issuetracker.google.com/issues/143281991 I hope it will be adressed. – Roar Grønmo Oct 31 '19 at 11:00
2

You have to build the project first (Build -> Make Project). I also had to restart Android Studio in order for previews to start working.

Alex H
  • 767
  • 8
  • 7