Failed to find style 'coordinatorLayoutStyle' in current theme

孤街醉人 提交于 2019-12-17 02:44:15

问题


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?


回答1:


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.




回答2:


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'



回答3:


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




回答4:


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



回答5:


 <style name="Theme.Shrine" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
</style>

Add in your material theme.




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




回答7:


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.




回答8:


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




回答9:


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.




回答10:


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.




回答11:


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




回答12:


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




回答13:


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?




回答14:


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




回答15:


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.




回答16:


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




回答17:


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'



回答18:


This is sdk 28 issue

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

compileSdkVersion 28

targetSdkVersion 28

To:

compileSdkVersion 27

targetSdkVersion 27



来源:https://stackoverflow.com/questions/49292487/failed-to-find-style-coordinatorlayoutstyle-in-current-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!