【问题标题】:CoordinatorLayout not working in Android Studio 3.1.3?CoordinatorLayout 在 Android Studio 3.1.3 中不起作用?
【发布时间】:2018-11-30 04:06:09
【问题描述】:

我知道这个问题已经被问过很多次了,但我已经尝试了大多数解决方案,但没有一个对我有用。 这是我第一次使用 android studio 3.1.3,我正在学习如何使用 android studio 中的基本模板选项创建一个简单的应用程序的教程。我面临的问题是;

渲染问题未能在其中找到样式“coordinatorLayoutStyle” 当前主题

我已尝试将其添加到 build.gradle 文件中:

编译'com.android.support:design:24.1.1'

这个也放到style.xml中

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

styles.xml

<resources>

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

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>


    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    Couldn't resolve resource @style/Widget.Design.CoordinatorLayout<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

build.gradle

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.notes"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:design:28.0.0-alpha3'
    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'
}

【问题讨论】:

  • This 帮我解决了类似的问题。试一试

标签: android android-studio material-design android-coordinatorlayout


【解决方案1】:

我遇到了同样的问题。我尝试了以下步骤from here,但问题仍然存在。我认为这是 android studio 3.0+ 中的一个常见问题,希望他们会在下次更新时修复它。在 Android Studio Preview 3.2 中它运行良好。 Download Android Studio Previewvisit here 了解如何与 Android Studio 稳定版一起运行它

或者您可以尝试将您的设计库版本降低到 27。(并且编译 sdk 版本也到 27)

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

【讨论】:

    【解决方案2】:

    尝试在 styles.xml 中的 Theme 之前添加“Base”,如下所示:-“Base.Theme.AppCompat.Light.DarkActionBar”

    【讨论】:

      【解决方案3】:

      此问题的永久解决方案:将构建 gradle(模块应用程序)更改为实现 com.android.support:appcompat-v7:28.0.0-alpha1

      【讨论】:

        【解决方案4】:

        更改您的构建 gradle(模块应用程序) 来自:com.android.support:appcompat-v7:28.1.1-alpha3

        到:com.android.support:appcompat-v7:27.1.1

        【讨论】:

        • 你能解释一下为什么降级依赖可以解决问题吗?
        • @Bajirang 依赖版本应该与 compileSdkVersion 匹配。因此降级到 27 还需要 OP 降级 compileSdkVersion。相反,请尝试this,它帮助我解决了类似的问题
        【解决方案5】:

        1.先试试这个:在 Gradle(模块应用程序)中为 appcompat 进行更改:

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

        2。如果它不起作用,请清理您的项目,然后再次构建它。 就我而言,它奏效了。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-08-02
          • 2011-06-14
          • 2018-02-18
          • 1970-01-01
          • 1970-01-01
          • 2021-11-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多