Android Studio does not show layout preview

AndroidAndroid LayoutAndroid Studio

Android Problem Overview


I'm using Android Studio 1.4

It has passed some time since the last time I've created a new project in android studio and today when I did it the android studio does not show anything from the layout preview. Its a blank window and says "Nothing to show".

I think it's related with the new support design library cuz I've never seen this new "default code". I've researched a bit and it's the new android material design guidelines ...

I've already done this:

  1. updated the SDK tools
  2. cleaned the project and rebuild it
  3. invalidated and restarted caches

...and still nothing.

Updated:

I decided to update 1.5.1 it's like this: it's giving me that rendering problem.. I think it's not showing correctly the lower right button, cuz I think it's supposed to be a button with a message icon in it and in my AS just shows the message icon (correct me if I'm wrong).

enter image description here

enter image description here

Android Solutions


Solution 1 - Android

Choose another theme (other than Holo, for example Theme)

Solution Image

When you create the style incorrectly or from an existing style, this problem usually occurs. So select the "Graphical Layout" select "AppTheme" (The tab with a blue star). And select any of the predefined style. In my case "Light" which should resolve the problem.

Try to 'Invalidate caches & restart'.

how to invalidate cache & restart

Restart your Android Studio by choosing this option. It may take some time.

Then, if still doesn't work try to rebuild your project.

Solution 2 - Android

This is a common problem . It can be easily solved by changing res/values/styles.xml to

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>
Steps :
  • Go to res/values/

  • open styles.xml

    • change from -> style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"

    • change to -> style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"

(Just prepend "Base." to "Theme".)


  • Save the file and check Preview now.

  • Preview Works Perfeclty now.

Solution 3 - Android

Check again for SDK update because API 23: Android N (preview) is now available, download it properly OR select the API 23: Android 6.0 from the top right of the preview window. check the image

enter image description here .
.
It (Android Studio) automatically selects the latest one even if it not properly installed. So,

What you need to do is :

  1. install the new one properly

OR

  1. click on the previous one.

Solution 4 - Android

Find Styles.xml in Values.(res/Values/Styles.xml) Change this

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to this:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Then clean and build project. Both of those you can do from build menu.

It worked for me.

Solution 5 - Android

Force refresh helped me.

It is at the top of the design tab.

enter image description here

Solution 6 - Android

I also go through same problem and do this simple work just go to res->values->style.xml and change

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

to

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Solution 7 - Android

Fast Forward to 2018 and we are still having this issue!

When I had this issue with Android Studio Canary 3.2 today, this is what I did:

I went to

File -> Settings -> Plugins

On the plugins list, I disabled Android Support by unchecking it.

Then, I selected Apply and then, OK.

After this I restarted Android Studio.

On restart, I repeated the process:

File -> Settings -> Plugins

But this time, on the plugins list, I enabled Android Support by checking it.

Then I restarted.

When Android Studio came on, I allowed Gradle do its thing, then I did:

File -> Sync Project with Gradle Files

When this was done, I reopened my xml files or refreshed them anyhow possible and everything was fine.

Yeah long route, but on a day when I have to deliver at work? It sure works!

TLDR: Just disable and re-enable Android Support and you will be fine

Solution 8 - Android

Clean build your project by going to Build > Clean build.

It helped me when I had the same problem.

Solution 9 - Android

Sometimes layout preview not show only in your current project, try open other project if in other project layout preview work well then the problem in your current project. in your current project try clean project, rebuild project, if still not working try make changes in your build.gradle app file, such add some implementation then gradle sync , check your layout preview works.

Solution 10 - Android

Switch from Blank Activity and use Empty Activity. Change your theme to for example Holo.Light.NoActionBar.

Unlike Blank, Empty is more stripped down thus you may need to add some stuff yourself. Such as add the 2 Override methods onCreateOptionsMenu and onOptionsItemSelected yourself if you need to manipulate controls on the ActionBar and such. Otherwise, no other significant difference.

Solution 11 - Android

I faced the exact problem when creating a new project, It seams to be related to the Appcompat Library to solve it:

I replaced : implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' by implementation 'com.android.support:appcompat-v7:27.1.1' And everything worked fine.

In conclusion, The problem is related to a bug in the library version.

But if it is necessary to use the Natesh bhat's solution is for you.

Solution 12 - Android

In my case, Android Studio created project including support library which version is RC or beta. So I tried downgrade version of support library, then worked.
If your library version is RC or beta, try downgrade.

Downgrade this
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

to this
implementation 'com.android.support:appcompat-v7:27.1.1'

and downgrade also compileSdkVersion, targetSdkVersion if you need.

Solution 13 - Android

This problem occurs due to theme compatibility issue. All you have to do is first navigate to res/values/styles.xml in the project view.There look for base application theme which by default should be the fourth line. It'd look similar to the following:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

Now, you just have to add 'Base. to the parent.

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Solution 14 - Android

It doesn't even show the "Hello World" in the preview when i started my first project,only displays 'Rendering problem' and 'Failed to instantiates one or more class'.This helps me out, try this..... in the left side menu, GoTo
base-> res-> values-> styles.xml
then write "Base." in the line <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
just before the Theme.AppCompat i.e <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Solution 15 - Android

In your top Android Studio menu, go to View > Tool Windows > Preview, then it should appear somewhere in the frame of Android Studio, you can move it to the desired place with the dented wheel tool in the Preview frame

Solution 16 - Android

For me, in Android Studio 3.6.1, while in the layout.xml file, clicking here showed the preview of the layout again. Android Studio 3.6.1 Screenshot

I Don't think the "tab" Preview exists anymore, it does now appear to me here: View > Tool Windows > Preview.

Solution 17 - Android

Change the Android version to use while rendering layouts in the IDE.

Go to your xml layout file -> Design -> change Android API version from Automatically Pick Best to a value in between your minimum and target sdk versions.

Solution 18 - Android

just refresh your layout by clicking this:

there will be a blue logo at the top left of the "layout-design" page

click and choose "Force Refresh Layout"

enter image description here

Solution 19 - Android

Please (change com.android.support:appcompat-v7:28.0.0-alpha3) or (com.android.support:appcompat-v7:28.0.0-rc02) to (com.android.support:appcompat-v7:28.0.0-alpha1) in build.gradle (Module: App).

Next click File -> Invalidate Caches / Restart

Need internet access.

It works for me Windows 10 and in Ubuntu 18.04.1 LTS

Solution 20 - Android

  1. Clean Project
  2. Rebuild Project
  3. Invalidate Caches / Restart

Solution 21 - Android

Android Studio Stuck At Initializing

android studio 4.1.2 suddenly stuck at initializing preview and XML preview is completely crashed. this is what I have done to fix the issue

  • go to C:/Users/username/AppData/Roaming/Google
  • Delete the entire AndroidStudio folder
  • Invalidate cache and restart your IDE

Solution 22 - Android

Android Studio Stuck At Initializing

  • Close the project
  • Delete .idea folder in project root folder
  • Open the project

Solution 23 - Android

Here is a simple solution that worked for me:

  1. Go to File -> Settings -> Apperance & Behavior -> System Settings -> Android SDK :

  2. Check Show Package Details which is located on the bottom right.

  3. Under the latest Android SDK version (for ex: Android 8.1 (Oreo)), check Google Play Intel x86 Atom System Image

  4. Now click apply button

This system image helps android studio to show layout preview.

Solution 24 - Android

Changing the theme(near the android symbol for changing API version) from AppTheme to anything else like DeviceDefault or Holo fixed the problem easily.

Solution 25 - Android

After so many flip-flap I realised that on xml Preview size above,on the left side of Apptheme we have Android Icon with ears click it and change to your target api in case that its not the same as it targeted on built.gradle

Solution 26 - Android

For me this problem keeps appearing after I run the APK at first time. Invalidating did not help.
However, I came with a workaround:
Just run the APK, and while it's running you can submit your changes clicking the "Lightning" button (Apply changes) next to to the "Run" button at the top right panel. Works charming for me, when making changes to the layout.

Solution 27 - Android

Follow a few steps:-
1) Clean Project
If 1 doesn't work then
2) Invalidate cache and restart 
If 2 doesn't work then 
3) run command in the project folder rm -r .idea

Solution 28 - Android

SOLUTION

  • Go to Preferences -> Plugin -> Installed.
  • Search "Android APK Support" -> Disable it
  • Invalidate Caches & Restart
  • Re-enable "Android APK Support" plugin
  • Restart
  • Done (It should resolve the issue. If you still see the issue on some custom views, just rebuilt/run the project)

PROBLEM

The reason of the issue (from my investigation) is related to some incorrect UI parts, for example:

  • Incorrect XML layout implementation
  • Incorrect styles implementation

So if the issue still persists, just try to figure out what part of your UI implemented wrong, and fix it.

Solution 29 - Android

use the below code in build.gradle and it will show your layout preview.

 configurations.all {
    resolutionStrategy {
        force 'androidx.core:core-ktx:1.6.0'
    }
}

Solution 30 - Android

I used the Debug "app" button enter image description here
and my problem was solved

Solution 31 - Android

Go to style.xml file and just add "Base" class before theme. as like

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
</style>

@Note: Replace Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar

and clear project.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCap.AlvezView Question on Stackoverflow
Solution 1 - Androidpiotrek1543View Answer on Stackoverflow
Solution 2 - AndroidNatesh bhatView Answer on Stackoverflow
Solution 3 - AndroidInzimam Tariq ITView Answer on Stackoverflow
Solution 4 - AndroidElifView Answer on Stackoverflow
Solution 5 - AndroidTpoM6oHView Answer on Stackoverflow
Solution 6 - AndroidAvnish NishadView Answer on Stackoverflow
Solution 7 - AndroidgbenroscienceView Answer on Stackoverflow
Solution 8 - AndroidDouglas CunhaView Answer on Stackoverflow
Solution 9 - Androiduser2702125View Answer on Stackoverflow
Solution 10 - AndroidkarView Answer on Stackoverflow
Solution 11 - AndroidMohammad TabbaraView Answer on Stackoverflow
Solution 12 - AndroidgalcyurioView Answer on Stackoverflow
Solution 13 - AndroidNikhil KapuView Answer on Stackoverflow
Solution 14 - AndroidAakash DasView Answer on Stackoverflow
Solution 15 - AndroidFausto ChecaView Answer on Stackoverflow
Solution 16 - AndroidAlexandreView Answer on Stackoverflow
Solution 17 - AndroidJaydevView Answer on Stackoverflow
Solution 18 - AndroidMohsen mokhtariView Answer on Stackoverflow
Solution 19 - AndroidVitalie BancuView Answer on Stackoverflow
Solution 20 - AndroidMike6679View Answer on Stackoverflow
Solution 21 - AndroidMalith IleperumaView Answer on Stackoverflow
Solution 22 - AndroidOmkar TView Answer on Stackoverflow
Solution 23 - AndroidMohan MunisifreddyView Answer on Stackoverflow
Solution 24 - AndroidPaulView Answer on Stackoverflow
Solution 25 - AndroidSamirView Answer on Stackoverflow
Solution 26 - AndroidLev KolomazovView Answer on Stackoverflow
Solution 27 - Androidneelkanth_vyasView Answer on Stackoverflow
Solution 28 - AndroidikhsanudinhakimView Answer on Stackoverflow
Solution 29 - AndroidPir Fahim ShahView Answer on Stackoverflow
Solution 30 - Android汝風留名View Answer on Stackoverflow
Solution 31 - AndroidrahulView Answer on Stackoverflow