android studio sdk version 22 exception during rendering: action_bar

JavaAndroidAndroid StudioSdkRendering

Java Problem Overview


When I create a new project on android studio it is not giving any problem. However, looking at the activity_main.xml design it is shows me this:

> Rendering Problems Exception raised during rendering: action_bar.

when I change sdk level 22 to 21 from the design page android studio shows nothing

How can I solve this problem? This is not important problem but I wondered how can I fix this.

Java Solutions


Solution 1 - Java

Yeah just had to adjust the Android level in the drop down. The design tab preview in API level 22 is broken right now. I looked that the stack trace for the error and it has something to do with needing the alpha channel. I'm sure Google will fix it Monday. :) enter image description here

Solution 2 - Java

ActionBar is deprecated in favor of Toolbar, which was added in API 21. However, the base theme for Android Studio's templates still seems to use ActionBar-based themes.

The solution is not to downgrade your build tools version, but rather to change your app's base theme. If you downgrade your build tools, you will miss out on support for the latest features added in Android 5.1 and later.

Your base theme is listed in AndroidManifest.xml under application/android:theme.

Go to res/values/styles.xml and change the parent attribute to a different base theme that doesn't rely on the deprecated ActionBar. In the unlikely case your app is API 21+, you can use Theme.Material. Otherwise, you'll need to use Theme.AppCompat.NoActionBar or define your own base theme.

Here's a styles.xml example:

<style name="AppTheme.Base" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

If you use this, be sure to put a Toolbar element in your XML layouts where you want the ActionBar to appear. You'll need to customize the Toolbar with child XML tags. I recommend using the <include> tag. As it says in the Toolbar documentation, Google's new design principles call for a change in visual style:

> In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

android.support.v7.widget.Toolbar is in the support library for pre-API 21 devices.

EDIT: As the first comment points out, Google has a blog explaining how to use the new Toolbar. http://android-developers.blogspot.kr/2014/10/appcompat-v21-material-design-for-pre.html

Solution 3 - Java

Sorry about the issue guys. The reason for the issue is that the rendering library is now trying to use more of the actual code from the appcompat library, in order to be more accurate. However, this has exposed some bugs in the Android Studio when the project is not built.

There is no need to update your gradle files or change the styles as some of the answers suggest.

The workaround is to build the project once and then refresh the rendering by clearing the cache. See the attached image for the refresh icon which clears the cache.

Refresh Button Location

Solution 4 - Java

This answer worked for me:

MyActivity extends AppCompatActivity

Instead of:

MyActivity extends ActionBarActivity   // now deprecated

Go back to your preview, clear cache and refresh!

Solution 5 - Java

Through days of frustration, I've finally found out the answer lies in the build.gradle of my app module! I've changed the buildToolsVersion from 22 to 21.1.2 to properly solve that exact exception like yours. It seems anything to do with API 22: Android 5.1 is giving hiccups at the moment. Hopefully Google will fix it soon.

Changing these lines in the build.gradle gave me a quick fix for this problem:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
}

Solution 6 - Java

I fixed it by changing buildToolsVersion "21.1.2", on build.gradle (Module: app),

Do not use buildToolsVersion "22"

Solution 7 - Java

Please use build API21 to see the preview. I am on mac and build 22 is broken/not working for me. When i switched back to build 21, i could see the preview.!

Solution 8 - Java

It turns out that you cannot use buildToolsVersion "22" or targetSdkVersion 22 because it fails to render properly. It seems it can only render the app when set to API 21 or lower at the moment because I was getting the same error and as soon as I changed it back to 21 it started working again. Just go into build.gradle(module:app) and change the API back to the latest version of API 21.

Solution 9 - Java

I solved it by rebuilding the project or module.

Solution 10 - Java

The solve:

Create a New folder values-v19

Create a styles.xml in this folder

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- For actionBar n' statusbar -->
    <item name="colorPrimary">#COLOR/item>
    <item name="colorPrimaryDark">#COLOR</item>

    <!-- For items -->
    <item name="colorAccent">#COLOR</item>
</style>

and is all :)

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
QuestionAli ArasView Question on Stackoverflow
Solution 1 - JavaDave FisherView Answer on Stackoverflow
Solution 2 - JavacolintheshotsView Answer on Stackoverflow
Solution 3 - JavaDeepanshuView Answer on Stackoverflow
Solution 4 - JavaMarkView Answer on Stackoverflow
Solution 5 - JavaReynolds R. G. G.View Answer on Stackoverflow
Solution 6 - JavaOscarView Answer on Stackoverflow
Solution 7 - JavaPranav2579View Answer on Stackoverflow
Solution 8 - JavaVimbainashe E MushayikwaView Answer on Stackoverflow
Solution 9 - JavaPober WongView Answer on Stackoverflow
Solution 10 - JavaHerberthObregonView Answer on Stackoverflow