Android Studio does not show layout preview - android

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:
updated the SDK tools
cleaned the project and rebuild it
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).

Choose another theme (other than Holo, for example Theme)
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'.
Restart your Android Studio by choosing this option. It may take some time.
Then, if still doesn't work try to rebuild your project.

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.

Force refresh helped me.
It is at the top of the design tab.

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
.
.
It (Android Studio) automatically selects the latest one even if it not properly installed. So,
What you need to do is :
install the new one properly
OR
click on the previous one.

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.

Clean build your project by going to Build > Clean build.
It helped me when I had the same problem.

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

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

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.

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.

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.

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.

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

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, it would look something like this:

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

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"

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

For me, in Android Studio 3.6.1, while in the layout.xml file, clicking here showed the preview of the layout again.
I Don't think the "tab" Preview exists anymore, it does now appear to me here: View > Tool Windows > Preview.

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.

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'
}
}

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

Clean Project
Rebuild Project
Invalidate Caches / Restart

Android Studio Stuck At Initializing
Close the project
Delete .idea folder in project root folder
Open the
project

Here is a simple solution that worked for me:
Go to File -> Settings -> Apperance & Behavior -> System Settings -> Android SDK :
Check Show Package Details which is located on the bottom right.
Under the latest Android SDK version (for ex: Android 8.1 (Oreo)), check Google Play Intel x86 Atom System Image
Now click apply button
This system image helps android studio to show layout preview.

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

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

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.

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

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

Related

Android Studio's Project Preview is Blank in a New Project

I just started learning some Android Studio, but when I create a project, the "Hello World" template isn't showing on the preview window, even if I make changes or add elements to the xml layout.
On my phone it shows perfectly, but I can't make it work on the IDE.
This is a known bug. Here are the many options to fix it:
Build > Clean Project
Build > Rebuild project
File > Invalidate Caches/Restart
If all else fails, go to your styles.xml located in res/values. Make sure you're using the parent="Theme.AppCompat.Light.NoActionBar" theme, instead of the default. (If you want a dark theme, do the obvious and change it to Theme.AppCompat.Dark.NoActionBar
Why this happens/Why this fixes it:
For some reason, Android Studio still uses the deprecated ActionBar by default and I don't think the layout editor supports it anymore. Thus it's crashing anonymously.
To use a Toolbar since the ActionBar is deprecated, follow this link:
https://developer.android.com/training/appbar/setting-up
(^ You can probably skip Step 1 in the above link)

Rendering problems:The following classes could not be instantiated

After update android studio to 2.1 when I create project with basic activity then it shows me error like below.
I tried to change android API and also change project theme in style.xml file,but still shows same error
I guess you get this error because you haven't add support.design library to your project correctly.
Doing these steps may solves your problem:
0- Change the target for the preview in the top right button of the preview area, like this:
1- Go to your SDK Manager and under the 'extras' section, check 'Android Support Library' and check it for installation. if you have done that before.
2- Add Support.design library to your build.gradle file:
compile 'com.android.support:design:24.1.0'
Then click "Synch Now" and gradle will get that library for you. then you can use support.design widgets in your UI.
3- Change res/values/styles.xml like this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"/>
I believe your SDK is not update correctly. Check again your SDK and download & install latest API correctly. for further detail check This post OR This One these both indicate the rendering problem solution.
Change the parent layout
<CoordinatorLayout> to <LinearLayout> or <RelativeLayout>
will solve your problem

Android Studio, design view empty

I'm using 1.4. I've tried to uninstall and reinstall again. still same problem. any solution?
Try just building the project: Build -> Make Project
If that doesn't work try cleaning the project: Build -> Clean Project
That happened to me as well and all I had to do was build the project. Then it was able to render it.
Go to app-res-values->styles.xml then;
Change,
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
this worked for me.
I just upgraded to Android Studio 1.5 and I ran into this same issue with new created projects. I tried invalidate the cache and rebuild the project. Sometimes that will fix the initial rendering, but any changes I make to the layout will not be reflected on the Design view.
The problem seems to be related to the embedded layout mechanism. After creating a new project (with Blank Activity), I got content_main.xml to display by removing the line tools:showIn="#layout/activity_main". Similarly, remove <include layout="#layout/content_main"/> from activity_main.xml and the Design view should render properly.
Did you try to remove android studio cache folders after uninstalling? they located on
C:\Users\<username>\.android, ..\.AndroidStudio1.4, ..\.gradle.
And then try to install studio again
Steps
Clean project
Build project
Close .xml files
Reopen them
That worked for me
Close android studio and reopen. Then rebuild project.
In my situation there was a silent error in my activity .xml file.
I accidentally positioned an item outside of my GridLayout (the child's layout_row/layout_column was too high). I'd expect Android Studio to report mistakes like this, but instead the design view just stops working.
So if your design view stops working and the other answers don't help, you might have an unreported error in your .xml file.

ERROR :rendering problems The following classes could not be found android.support.v7.internal.widget.ActionBarOverlayLayout

I am just a beginner to android app development. When i created a new project on Android Studio 1.1.0,
it gives up this error
"rendering problems
The following classes could not be found android.support.v7.internal.widget.ActionBarOverlayLayout"
Now i have searched about this on google, and i found possibly 3 solutions given by most of the people.
They say:
Either change the api (from preview window pane) from 22 to 21, or
Change the App Theme from "Project Theme" to any other theme.
be sure to have imported right appcompat-v7 library in your project structure -> dependencies,
Refer these steps:
Add the support library feature project identifier to the dependencies section. For example, to include the appcompat project add compile "com.android.support:appcompat-v7:18.0.+" to the dependencies section, as shown in the following example:
dependencies {
...
compile "com.android.support:appcompat-v7:18.0.+" }
Note: My android support lib is up-to-date (installed it using SDK Manager).
Following first two steps, removed the error. But I feel that these are not the permanent solutions, the Second step seems just like a temporary workaround. I have doubts about the First step also, that if to remove the error, we change api from 22 to 21, then at the end, our app wont work in Android 5.1.1(API 22), it would be restricted to Android 5.0.1 and below only (API 21). Are my doubts valid?
Regarding the third step, is it the permanent solution to this problem?
P.S : Sorry for mismatching tags, wasn't allowed to add exact tags due to site reputation
Fix res/values/styles.xml like so:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"/>
Detailed explanation as requested: Theme.AppCompat.Light.DarkActionBar is a subclass of the superclass Base anyway. Ctrl+click (Android Studio) on it and you will be taken to the source:
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar" />
We didn't change anything, we just defined it more precisely.
This is a known bug since Android Studio build 1.1 (it is also still in 1.2 and 1.3 preview). Switching the preview's API level from 22 to 21 fixes the for most people. While waiting for a fix you could try it as well.
Originally answered here : Rendering problems in Android Studio v 1.1 / 1.2
Just reposting
Modify src/res/values/styles.xml
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"></style>
Then select API22, you'll find this problem fixed!
After this error, I'm using :
API-22 Android 5.1.1 and still this problem exist.But you can at the top of the android studio toolbar, Choose:
Material Light -> Material Light
and then you can see the preview with Toolbar and light theme.
Hope this helps.
I fixed this problem by switching to the Holo Dark theme, then back to the App theme. I just clicked the button above the viewer that says App theme next to the rotate view in Android Studio. About 10% of the time, that alone doesn't work and I also have to change the API of the viewer from 22 to 19.
No idea why this works, but the suggestions provided above did not work for me.
You don't need to change the theme. Maybe your're extending ActionBarActivity (deprecated) instead of just Activity. Change it, and build the project.
If you do change the activity from ActionBarActivity to just Activity, don't forget to import the Activity itself. That is
import android.app.Activity
It sucks but hey, it's their fault and not ours.
Also you can simply change the theme by pressing the "AppTheme" and choose Holo.Light.DarkActionBar. It updates the styles.xml file automatically.After that, rebuild the project.
I did all these and it works for me though i think them guys at Google and IntelliJ should do something about this rendering problem since we have been told to move from Eclipse to Android Studio

Android Studio Rendering Problems : The following classes could not be found

I just update Android Studio, and when I restarted it, the preview window rendering failed, and I was told that
The following classes could not be found:
- android.support.v7.internal.widget.ActionBarOverlayLayout
If someone can tell me what can I do to fix this rendering problem? Thank you.
You have to do two things:
be sure to have imported right appcompat-v7 library in your project structure -> dependencies
change the theme in the preview window to not an AppCompat theme. Try with Holo.light or Holo.dark for example.
Please see the following link - here is where I found a solution that worked for me.
Rendering problems in Android Studio v 1.1 / 1.2
Changing the Android Version when rendering layouts worked for me - I flipped it back to 21 and my "Hello World" app then rendered the basic activity_main.xml OK - at 22 I got this error. I borrowed the image from this posting to show you where to click in the Design tab of the XML preview. What is wierd is that when I flip back to 22 the problem is still gone :-).
I had to change my values/styles.xml to
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Before that change, it was without 'Base'.
(IntelliJ IDEA 2017.2.4)
I have faced this issue when I introduced additional supporting libraries in my project IntelliJ IDEA
So for me "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
To use the class ActionBarOverlayLayout you need to include this in the dependencies section of build.gradle file:
compile 'com.android.support:design:24.1.1'
Sync the project once again and then you will find no problem
I faced this error when I created second activity in my project in the newly updated Android Studio,I solved it simply by copy pasting the whole xml code from first layout to the second and then I just removed the code that's unnecessary.

Categories

Resources