我正在使用最新版本的Android Studio(3.0),以及最新的构建工具(27)和类似的API级别。
设计选项卡中没有呈现布局,这给我带来了很多麻烦,特别是因为我正在使用Coordinator Layout。
我该如何解决这个问题?
我正在使用最新版本的Android Studio(3.0),以及最新的构建工具(27)和类似的API级别。
设计选项卡中没有呈现布局,这给我带来了很多麻烦,特别是因为我正在使用Coordinator Layout。
我该如何解决这个问题?
<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>
根据@Chris的建议,如果IDE在Widget.Support或Widget.Design中未找到CoordinatorLayout,请直接开始输入“CoordinatorLayout”,它应该会给出一些选项。@style/Widget.Support.CoordinatorLayout
下面。 - Chris事实证明,新的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'
28.0.0-alpha3
版本的支持库,改为降级到28.0.0-alpha1
版本的支持库,正如这个答案所建议的:https://dev59.com/RVUM5IYBdhLWcg3wINak#51091869。 - Livvenbuild.gradle
(module)中将 implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
的 alpha 3 改为 alpha 1。同步后,你就可以进行操作了。我花了一整天的时间来尝试解决这个问题,但都没有成功。希望这能有所帮助。我曾经也面临同样的问题。从布局预览窗口更改主题并没有帮助到我。
解决方案: 我更新了我的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
<style name="Theme.Shrine" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
</style>
<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'
}
它对我来说完美地运作了。希望这对你有用。
tools:showIn
属性,然后将其移动到了一个viewpager中。之前它嵌入在主机活动中,尽管lint没有捕获它,这有点令人惊讶。<style name="Coordinator">
<item
name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
</style>
<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错误。
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'
}
这解决了我的问题
谢谢