在当前主题中找不到样式 'coordinatorLayoutStyle'

Failed to find style 'coordinatorLayoutStyle' in current theme

我正在使用最新版本的 android studio (3.0),以及最新的构建工具 (27) 和类似的 API 级别。

布局未在设计选项卡中呈现,这造成了很多麻烦,尤其是当我使用协调器布局时。

如何解决这个问题?

这可能存在的问题:https://issuetracker.google.com/issues/37048767

使用其他版本的 Android 进行渲染(比如 Android API 22)。

或检查是否有错别字或无效的 XML 条目。

参考这里:Missing styles. Is the correct theme chosen for this layout?

感谢您的回复,我找到了修改代码的解决方案,

我在片段的父布局中启用了 tools:showIn 属性,我将其移动到 viewpager,它之前嵌入在主机中 activity,但 lint 没有捕捉到它,这有点意外。

我通过简单地将这一行插入到应用主题中解决了这个渲染问题(应用主题通常放在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.

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

添加您的 material 主题。

我也遇到了同样的问题。没有什么比从布局预览更改主题更能帮助我了。window。

解决方案: 我将 build.gradle(app) 更新为:

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

还有一件事:

compileSdkVersion 27
targetSdkVersion 27

我认为这是 android studio 3.0+ 中的常见问题, 希望他们会在下次更新时修复它。在 Android Studio Preview 3.2 中它运行良好。 Download Android Studio Preview

顺便说一句,在 Android Studio 的设计视图中,如果我将以下内容添加到 styles.xml 文件中:

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

并将以下内容添加到布局的 xml 资源文件中的 CoordinatorLayout

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

然后,至少设计视图会停止生成缺少的 coordinatorLayoutStyle 错误。

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'build.gradle(module) 将 alpha 3 更改为 alpha 1.sync,你应该可以开始了。我花了将近一天的时间试图弄清楚这一点。 none 这些答案对我有用。希望这有帮助

事实证明,当您创建新项目时,新 SDK 28 不幸地在 Android Studio 上引入了这个错误。

如何解决:

检查您的 build.gradle (模块:app) 文件并更改:

compileSdkVersion 28
targetSdkVersion 28

收件人:

compileSdkVersion 27
targetSdkVersion 27

此外,请确保您使用的依赖项版本正确:

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

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

只需将 coodrinatorLayoutStyle 添加为 style.xml 中的一项,它对我有用。

我的 Android 工作室版本 3.1.3。
我正在卸载所有 SDK 版本 28。
步骤是打开 SDK 管理器 > SDK 平台 > 显示包详细信息 > 取消勾选 SDK 28 > 应用并创建新项目。

对于 Android Studio 3.1.4 用户: 我已经尝试过标记答案,但它对我不起作用。 插入这一行:

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

进入应用程序主题无法解决渲染问题,因此我撤消了该更改。

解法: 我在我的 build.gradle(Module:app) 文件中进行了此更改:

变更前:

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

修改后:

android {
   compileSdkVersion 27
      defaultConfig {
         targetSdkVersion 27
      }
   }
}

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

它非常适合我。希望有用。

我有同样的问题但是在 Android studio 3.1.4

因此,起初我在 build.gradle

中做了以下操作

替换为:

实施'com.android.support:appcompat-v7:28.0.0-rc01'

实施'com.android.support:design:28.0.0-rc01'

实施'com.android.support:support-v4:28.0.0-rc01'

这样:

实施'com.android.support:appcompat-v7:28.0.0-alpha1'

实施'com.android.support:design:28.0.0-alpha1'

实施'com.android.support:support-v4:28.0.0-alpha1'

但不知何故,在项目重建后问题再次重复。

所以,我是这样走的:

这是我的项目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
}

这里是应用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'
}

这解决了我的问题

谢谢

只需更改实现 'com.android.support:appcompat-v7:28.0.0-alpha3' 和 'com.android.support:design:28.0.0-alpha3' 到 alpha 1。 我就是这样解决问题的。

我会 post 一个答案 其他答案可能有用,但没有人需要下载预览版并且做 Material 没有操作栏的设计不是 的方法开始 使用 Android Studio
开发应用 我们的 Android Studio 版本是 3.1.4 我们默认的 API 是 28 我们的 FIX 是降级到 API 26 您可以通过单击文件 -> 项目结构然后突出显示 app 在属性选项卡下将编译 Sdk 版本更改为 API 26现在单击 Falavors 选项卡并将 Target Sdk 版本更改为 26
然后在 build.gradle(module:app) 添加这些更改

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'

我想人们总是可以通过 Google 学习使用 ToolBar

来证明这个缓慢的 FIX 是合理的

我在 IDE 中更新所有 SDK 工具并将 Android Studio 更新到 3.2.1

时解决了这个问题

它对我有用试试看

   compileSdkVersion 28
        defaultConfig {
            minSdkVersion 16
            targetSdkVersion 28
           }

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

这是 sdk 28 问题

检查您的 build.gradle(模块:app)文件并更改:

compileSdkVersion 28

targetSdkVersion 28

收件人:

compileSdkVersion 27

targetSdkVersion 27