在Android Studio 3.1.3中,CoordinatorLayout无法正常工作?

6
我知道这个问题已经被问了很多次,但我尝试过大部分的解决方案,但都不适用于我。这是我第一次使用Android Studio 3.1.3,并且正在跟随教程使用基本模板选项创建一个简单的应用程序。我遇到的问题是: enter image description here

渲染问题:在当前主题中找不到“coordinatorLayoutStyle”样式

我尝试将以下内容添加到build.gradle文件中:

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

1
这个帖子帮助我解决了类似的问题。你也可以试一试。 - Kathir
5个回答

6
我遇到了相同的问题。我尝试按照这里的步骤进行操作,但问题仍然存在。我认为在Android Studio 3.0+中这是一个常见的问题,希望他们在下一次更新中解决它。在Android Studio预览版3.2中,它可以正常工作。下载Android Studio预览版,并访问此处了解如何与Android Studio稳定版本一起运行。

enter image description here

或者您可以尝试将设计库版本降低至27(同时将编译SDK版本也设置为27)。

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

1
尝试在styles.xml中将"Theme"之前添加"Base",如下所示:- "Base.Theme.AppCompat.Light.DarkActionBar"

1

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


0

更改你的构建 Gradle(module app)

从:com.android.support:appcompat-v7:28.1.1-alpha3

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


你能解释一下为什么降级依赖项会解决问题吗? - Robert
@Bajirang 依赖版本应该与compileSdkVersion匹配。因此,降级到27也需要将compileSdkVersion降级。相反,尝试使用这个,它帮助我解决了类似的问题。 - Kathir

0

1. 首先尝试这个:在Gradle(模块app)中更改appcompat:

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

2. 如果它不起作用,请清理您的项目,然后再次构建它。在我的情况下,它有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接