101

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

Lii
  • 11,553
  • 8
  • 64
  • 88
Cap.Alvez
  • 1,363
  • 3
  • 17
  • 19
  • 1
    add screenshot link to this problem, it may have many reasons ;-) – piotrek1543 Dec 28 '15 at 20:01
  • 1
    @piotrek1543 updated – Cap.Alvez Dec 28 '15 at 20:07
  • 2
    wow, I haven't expected that. Ok, update your Android Studio to latest version – piotrek1543 Dec 28 '15 at 20:09
  • 1
    @piotrek1543 just updated to AS 1.5.1 and it's giving me that weird rendering problem (updated screenshot above). – Cap.Alvez Dec 28 '15 at 20:46
  • 4
    @Cap.Alvez Can you try to change the App theme to for example Holo.Light.NoActionBar – kar Dec 28 '15 at 20:47
  • 1
    @keshk it's the same ... this is really weird – Cap.Alvez Dec 28 '15 at 21:36
  • 2
    @Cap.Alvez That usually works for me. One other thing I can think of is did you start a 'Blank' Activity or 'Empty' Activity? If you did Blank, can you try to make a new project for testing using Empty and set Theme to Holo.Light as mentioned earlier. – kar Dec 28 '15 at 21:45
  • 1
    @keshk If I start 'empty' activity is all good, it shows everything. But I would like to know why If I use 'Blank' It won't work because I would like to test some things with this new android Material design support library : ( – Cap.Alvez Dec 28 '15 at 21:52
  • 1
    @Cap.Alvez Don't have exact answer to that. It likely has got issues with missing library files of some sort. What extras do you need from Blank which Empty doesn't have? Are you talking about the 2 override methods onoptions and onItemSelected? In terms of the library support, I would presume it is available regardless of empty or blank. – kar Dec 28 '15 at 22:01
  • 1
    "invalidated and restarted caches" did trick for me. and worked. – Rumit Patel Feb 16 '18 at 11:41
  • 1
    This is a common problem in most of the systems, try this simple fix https://stackoverflow.com/a/50828173/6665568 – Natesh bhat Sep 19 '18 at 14:15
  • 1
    Invalidating and restarting cache worked for me. – Taslim Oseni Oct 20 '18 at 15:39
  • I downgraded Android Studio from `Dolphin` to `Chipmunk` when Preview windows wrote: ["the following classes could not be instantiated"](https://stackoverflow.com/questions/64646226/the-following-classes-could-not-be-instantiated-com-google-android-material-c/74125651). – CoolMind Oct 19 '22 at 13:47

36 Answers36

130

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.

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • 2
    Invalidate caches worked for me when I had an empty Preview tab with no device config buttons. – Aleksander Niedziolko Jun 12 '18 at 13:26
  • As I didn't restart Android Studio for a couple of weeks. Was hibernating my laptop. Doing so worked for me. Thanks! – sud007 Jun 13 '18 at 05:49
  • I was frustrated because there was no blue star. But then I found that the Theme icon on my tool bar is two concentric circles, with the inner one divided vertically in half with one side white and the other black. – ROBERT RICHARDSON Jun 22 '18 at 22:26
  • What is I want to use App Theme ? – Agile_Eagle Jul 11 '18 at 09:39
  • If you want to use app theme then view the answer of Natesh bhat below – user2174870 Aug 18 '18 at 12:27
  • Empty projects with "empty" features just needs developer to chose an theme, as shown above. It is not a bug, it simply does not have any theme selected. (Kubuntu 18.04.1 there was no need to Invalidate caches, simply select the theme). – Arthur Zennig Aug 23 '18 at 20:42
88

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.

Natesh bhat
  • 12,274
  • 10
  • 84
  • 125
20

Force refresh helped me.

It is at the top of the design tab.

enter image description here

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72
16

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

  2. click on the previous one.

Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69
16

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.

Elif
  • 345
  • 3
  • 14
  • It worked for me. It would be nice to have an additional explanation why it's happening. I suspect some of Android Studio's tutorials are not updated to reflect change in theme's class hierarchy. – Yevgen Aug 19 '18 at 10:47
  • 1
    You're a genius! How did you even know that I'm using Theme.AppCompat.Light.DarkActionBar? – dan dan Dec 06 '18 at 01:53
  • Hello world app is initialized with Theme.AppCompat.Light.DarkActionBar. And everytime I open a new project I encountered this problem. Apparently lots of other people encounter same problem. – Elif Dec 06 '18 at 02:02
8

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

It helped me when I had the same problem.

Douglas Cunha
  • 164
  • 2
  • 8
7

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">
Zoe
  • 27,060
  • 21
  • 118
  • 148
Avnish Nishad
  • 1,634
  • 1
  • 17
  • 18
6

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

gbenroscience
  • 994
  • 2
  • 10
  • 33
6

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.

user2702125
  • 141
  • 2
  • 4
6

If the project contains multiple themes, it should be ensured that the right theme is selected in the 'Theme for preview' option.

In android studio dolphin (version 2021.3.1), it would look something like this:

preview-tab

dropdown

ganjaam
  • 1,030
  • 3
  • 17
  • 29
4

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.

kar
  • 4,791
  • 12
  • 49
  • 74
4

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">

Aakash Das
  • 41
  • 3
4

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.

Mohammad Tabbara
  • 1,438
  • 1
  • 16
  • 31
  • There is an issue with the app compact as you said. Alternatively, if you are working with implementation 'com.android.support:appcompat-v7:27.1.1 you can change the last number sync gradle and then change it back. For me, this resolved the my issue. – George Jul 22 '18 at 11:51
4

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.

galcyurio
  • 1,776
  • 15
  • 25
4

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">
Zoe
  • 27,060
  • 21
  • 118
  • 148
3

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

Mohsen mokhtari
  • 2,841
  • 1
  • 30
  • 39
3

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

Fausto Checa
  • 163
  • 13
3

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.

Alexandre
  • 349
  • 6
  • 10
2

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.

Jaydev
  • 1,794
  • 20
  • 37
2

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'
    }
}
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81
1

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

Vitalie Bancu
  • 171
  • 1
  • 11
1
  1. Clean Project
  2. Rebuild Project
  3. Invalidate Caches / Restart
Mike6679
  • 5,547
  • 19
  • 63
  • 108
1

Android Studio Stuck At Initializing

  • Close the project
  • Delete .idea folder in project root folder
  • Open the project
Omkar T
  • 755
  • 8
  • 19
1

The other solutions here I have checked, but no luck. Then what I have done that, I have removed one by one element from my layout design, to see that which part of the xml layout causes the problem. So, just when I have removed this:

<FrameLayout
                android:id="@+id/mapFrameLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="60dp"
                android:visibility="invisible">

                <androidx.fragment.app.FragmentContainerView
                    android:id="@+id/map"
                    android:name="com.google.android.gms.maps.SupportMapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </FrameLayout>

Suddenly, my layout preview has shown with the rest of element/widgets. Voila!

For All : Then, paste again that above codes. Then, at the top right corner of layout preview where the red exclamation mark appear, (toggle visibility of issue panel), I clicked on it, and all the problems are now shown. I clicked one of the problems which said about fragment problem, then on the right side the problem details appear with the line "Do not warn for this session". Then I clicked on it. And the problem has gone as well as layout preview started showing.

halfer
  • 19,824
  • 17
  • 99
  • 186
Noor Hossain
  • 1,620
  • 1
  • 18
  • 25
1

I had the same issue this is how I resolved it:

Solution Sample

0

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.

Mohan
  • 1,164
  • 15
  • 18
0

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

Paul
  • 1
0

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

Samir
  • 6,405
  • 5
  • 39
  • 42
0

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.

Lev Kolomazov
  • 87
  • 1
  • 7
0
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
neelkanth_vyas
  • 192
  • 1
  • 7
0

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
Malith Ileperuma
  • 926
  • 11
  • 27
  • Deleting these folders reset the entire Android Studio installation..had to install all from the scratch.. – RAINA Jan 02 '23 at 03:57
0

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.

ikhsanudinhakim
  • 1,554
  • 16
  • 23
0

I encountered this situation in two scenarios.

FragmentContainerView Usage

  • On new versions of Android Studio, if you're using FragmentContainerView, IDE expects an initial layout preview as "tools:layout" attribute. Below is an example, change fragment_preview with your desired layout.
<androidx.fragment.app.FragmentContainerView
    ...
    tools:layout="@layout/fragment_preview" />
            

Lottie Animations Usage

  • On new versions of Android Studio, if you're using LottieAnimations, IDE struggles on displaying dynamic structure on preview. I coped this issue with setting tools:lottie_rawRes attributes background as null. This way on compile time IDE do not try to display the animation preview and it's displayed only on runtime.
<com.airbnb.lottie.LottieAnimationView
        ...
        app:lottie_rawRes="@raw/loading"
        tools:lottie_rawRes="@null"/>
            
0

Try removing and adding back views one by one

I tried everything, updating Android studio, plugins, emulator, gladle version. Other that that, I've invalidated cache and restarted several times.

What I found the problem for me was in one a LinearLayout under a ScrollView. Why because under that LinearLayout we had a custom view which was having rendering issues. So if you've also tried everything and nothing works, I'd suggest to try to remove the parent as well as child views one by one and maybe you'll find what View/ViewGroup is causing the issue.

shahrukhamd
  • 259
  • 6
  • 6
-2

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.

BDL
  • 21,052
  • 22
  • 49
  • 55
rahul
  • 37
  • 2
-2

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

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83