我刚刚第一次安装了Android Studio,以学习如何制作应用程序。但我偶然发现了一个错误,每当我创建一个项目时都会遇到这个错误。我得到的错误是这样的:
"Render problem - Failed to find style 'coordinatorLayoutStyle' in current Theme.
所以我做了一些搜索,找到了多个像我这样的帖子,对于每个人来说,这个问题的解决方案是添加以下代码。
<item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
我将这行代码添加到应用程序主题中,现在又收到了另一个错误。
呈现问题-无法解析资源@style/Widget.Design.CoordinatorLayout
styles.xml看起来像这样
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
<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" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
这一行
@style/Widget.Design.CoordinatorLayout
标记为红色,并将鼠标悬停在其上时,显示"symbol cannot be resolved“
另外,这是我的build.gradle文件,在这里你可以看到我使用的是最新的设计库,并且我是在API28上编译的
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.fredrikbiten.myapplication2"
minSdkVersion 15
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.1'
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'
}
我没有写任何代码行,这都是创建项目时的默认设置。有谁知道解决方案吗?
发布于 2018-06-09 22:44:54
这是由API 28引起的问题。只需移动到API 27 (编译和目标版本、依赖关系等),等待他们修复此问题。
我还没有找到一个真正的解决方案,重建,清理,无效缓存,等等。一个尝试了所有StackOverflow的答案,他们也不工作。
发布于 2018-06-09 07:30:29
所以我让它起作用了。我将API级别和设计版本从28更改为27。现在起作用了。
发布于 2018-06-09 03:32:28
在我的例子中,我添加了您所描述的行:
<item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
对AppTheme,而不是对AppTheme.NoActionBar和问题已解决!希望这篇文章能把你引向正确的方向。
https://stackoverflow.com/questions/50767196
复制相似问题