65

I'm using the latest version of android studio (3.0), along with latest build tools (27) and similar API level.

The layout does not get rendered in the design tab and it's causing a lot of trouble especially that I'm using coordinator layout.

How do I get around this problem?

Jeet Dholakia
  • 850
  • 1
  • 6
  • 18

18 Answers18

109

I solved this rendering problem by simply inserting this line into the application theme (the app theme is usually placed in styles.xml).

[SDK 28]

<style name="AppTheme">
  <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
</style>

[SDK 27]

<style name="AppTheme">
  <item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
</style>

As suggested by @Chris. If the IDE does not find the CoordinatorLayout in Widget.Support or Widget.Design, just start typing "CoordinatorLayout" and it should give you some options.

T-igra
  • 1,292
  • 1
  • 9
  • 11
  • 7
    Wasted hours on this. Do you know why it happens ? I had no problem before but suddenly – M at Apr 11 '18 at 16:26
  • 4
    Android is so weird sometimes *eyeroll* Thanks this fixed the issue for me. – Arbitur Apr 30 '18 at 14:29
  • 7
    Thanks. It's ridiculous that Android Studio requires this. – Monte Creasor May 08 '18 at 23:02
  • 8
    Good for you, it happen for me on starting up the Hello World app :D mean they introduce a built-in error :)) – Hassan Faghihi May 20 '18 at 05:54
  • 1
    Unbelievably this works. But for god's sake, why? But did you know that I then **deleted** that line...and it still works! Indicates that somehow the editor got into a wicked state and this line somehow fixes it. Perhaps an invalidate/restart would have worked too? – SMBiggs May 23 '18 at 16:09
  • 1
    Oops, spoke too soon. Added another widget and the error popped back up. Guess I'll have to keep that line in my `styles.xml`. – SMBiggs May 23 '18 at 16:21
  • 2
    And when you say application theme, you mean the styles.xml correct? – DanMossa Jun 16 '18 at 06:58
  • @DanMossa, yes - styles.xml. Or place the app theme in any .xml file in the /values folder. – T-igra Jun 16 '18 at 20:08
  • 7
    If it is saying it doesn't exist, trying just typing beginning to type "Coord" and it should give you some options. Mine was under `@style/Widget.Support.CoordinatorLayout` – Chris Jul 27 '18 at 03:10
  • yeah it is under support public class CoordinatorLayout extends ViewGroup implements NestedScrollingParent2 java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.support.design.widget.CoordinatorLayout – Manoranjan Aug 17 '18 at 09:33
35

Turns out the new SDK 28 is unfortunately introducing this error on Android Studio when you create a new project.

How to solve:

Check your build.gradle (Module: app) file and change:

compileSdkVersion 28
targetSdkVersion 28

To:

compileSdkVersion 27
targetSdkVersion 27

Also, make sure you are using the right dependencies version:

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
Geraldo Neto
  • 3,670
  • 1
  • 30
  • 33
  • 4
    Alternatively stay on SDK 28 and instead downgrade the support library versions from `28.0.0-alpha3` to `28.0.0-alpha1`, as suggested in this answer https://stackoverflow.com/a/51091869/1488656 – Livven Jul 15 '18 at 22:56
  • That's it, changing the SDK 28 to 27 and sync Gradle solved the problem. – Thiago Souza Aug 31 '18 at 01:05
  • As suggested by @Livven, there are some issues with the Support Library 28.0.0-alpha3. – Geraldo Neto Mar 18 '19 at 04:57
11

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' in build.gradle(module) change alpha 3 to alpha 1. sync and you should be good to go. I spent almost a day trying to figure this out. none of these answers worked for me. hope this helps

Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
tony Macias
  • 226
  • 3
  • 9
7

I was also facing the same problem. Nothing like changing theme from Layout preview window helped me.

Solution: I updated my build.gradle(app) with:

dependencies {
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:design:27.0.2'
}

One more thing:

compileSdkVersion 27
targetSdkVersion 27
Anu Bhalla
  • 422
  • 4
  • 11
  • 2
    Alternatively stay on SDK 28 and instead downgrade the support library versions from `28.0.0-alpha3` to `28.0.0-alpha1`, as suggested in this answer https://stackoverflow.com/a/51091869/1488656 – Livven Jul 15 '18 at 22:58
6
 <style name="Theme.Shrine" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
</style>

Add in your material theme.

Muzammil Husnain
  • 1,218
  • 1
  • 10
  • 24
6

For Android Studio 3.1.4 users: I've tried marked answer but it didn't work for me. Inserting this line:

<style name="AppTheme.NoActionBar">
   <item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
</style>

into the application theme doesn't solve the rendering problem so I've undone that change.

Solution: I've made this changes in my build.gradle(Module:app) file:

Before change:

android {
   compileSdkVersion 28
      defaultConfig {
         targetSdkVersion 28
      }
   }
}

dependencies {
   implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
   implementation 'com.android.support:design:28.0.0-rc01'
}

After change:

android {
   compileSdkVersion 27
      defaultConfig {
         targetSdkVersion 27
      }
   }
}

dependencies {
   implementation 'com.android.support:appcompat-v7:27.1.1'
   implementation 'com.android.support:design:27.1.1'
}

It worked for me perfectly. Hope that will be useful.

kaspiotr
  • 558
  • 1
  • 9
  • 11
5

Thanks for the response, I found the solution tinkering with the code,

I had tools:showIn attribute enabled in the parent layout of a fragment, which I moved to a viewpager, it was previously embedded in a host activity, lint did not catch it though, which is a bit surprising.

Jeet Dholakia
  • 850
  • 1
  • 6
  • 18
2

I think it is a common issue in android studio 3.0+, Hopefully they will fix it next update. In the Android Studio Preview 3.2 it works fine. Download Android Studio Preview enter image description here

Nishan
  • 3,644
  • 1
  • 32
  • 41
1

As an aside, in design view of Android Studio, if I add the following to the styles.xml file:

<style name="Coordinator">
    <item 
    name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
</style>

and add the following to the CoordinatorLayout in the layout's xml resource file

<android.support.design.widget.CoordinatorLayout
    android:theme="@style/Coordinator"
    android:orientation="vertical"
    android:id="@+id/sample_layout_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/sample_background"
    tools:theme="@style/Coordinator">

then, at least, the design view stops generating the missing coordinatorLayoutStyle error.

Phillip
  • 11
  • 1
1

My Android studio version 3.1.3.
i'm worked with uninstall ALL SDK version 28.
Step is Open SDK Manager > SDK Platforms > Show package Details > Untick SDK 28 > apply and Create new project.

landongtom
  • 11
  • 1
1

I have the same problem but on the Android studio 3.1.4

So, at first I have done the following in build.gradle

Replace this:

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

implementation 'com.android.support:design:28.0.0-rc01'

implementation 'com.android.support:support-v4:28.0.0-rc01'

with that:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

implementation 'com.android.support:design:28.0.0-alpha1'

implementation 'com.android.support:support-v4:28.0.0-alpha1'

But somehow after project rebuild the problem repeats again.

So, I have go this way:

Here is my project gradle.build

buildscript {
    ext.kotlin_version = '1.2.41'
    ext.android_support = '27.1.1'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And here app build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "*****.******"//Replace with your own ID
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

And this solve my problem

Thank you

Georgy Ivanov
  • 39
  • 1
  • 4
1

I will post an answer The other answers may work but no one should need to download Preview Version and doing Material Design with no Action Bar is not the way to START developing apps with Android Studio
Our version of Android Studio is 3.1.4 Our default API is 28 Our FIX is to downgrade to API 26 YOU do this by clicking File -> Project Structure then highlight app Under the Properties TAB Change Compile Sdk version to API 26 Now click on the Falavors TAB and change Target Sdk version to 26
Then in build.gradle(module:app) add these changes

implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'

I guess one could always justify this slow FIX by Google to learn to use the ToolBar

Vector
  • 3,066
  • 5
  • 27
  • 54
0

This maybe existing issue: https://issuetracker.google.com/issues/37048767

Render using other versions of Android (say Android API 22).

Or check for any typos or invalid XML entries.

Refer here: Missing styles. Is the correct theme chosen for this layout?

Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126
0

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
</style>

just add coodrinatorLayoutStyle as an item in style.xml and it worked for me.

0

Just Change implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' and 'com.android.support:design:28.0.0-alpha3' to alpha 1. That's how i solved the problem.

SoufianeK
  • 1
  • 3
0

I solve this problem when update all SDK tools in IDE and update Android Studio to 3.2.1

0

its working for me try it

   compileSdkVersion 28
        defaultConfig {
            minSdkVersion 16
            targetSdkVersion 28
           }

 implementation 'com.android.support:appcompat-v7:28.0.0'
 implementation 'com.android.support:design:28.0.0'
Neeraj Singh
  • 610
  • 9
  • 15
0

This is sdk 28 issue

Check your build.gradle (Module: app) file and change:

compileSdkVersion 28

targetSdkVersion 28

To:

compileSdkVersion 27

targetSdkVersion 27

Sachin Jagtap
  • 527
  • 6
  • 16