【问题标题】:Issues with AppCompat in Android Studio Affecting Layout EditorAndroid Studio 中影响布局编辑器的 AppCompat 问题
【发布时间】:2018-12-29 22:55:42
【问题描述】:

所以我刚刚安装了 Android Studio 并开始遵循 Android 开发者网站上的“构建您的第一个应用程序”指南。我按照那里的指南创建了一个简单的空应用程序,屏幕中间只有“Hello World”文本。

在模拟器上运行应用程序时它工作正常,但是当我在布局编辑器中查看蓝图时,它是空的。它应该在中心显示“Hello World”TextView 以及显示约束。

我在下面收到这些消息:

`Render Problem

Failed to load AppCompat ActionBar with unknown error.   
Tip: Try to refresh the layout.`

...和

Failed to Instantiate One or More Classes

The following classes could not be instantiated:
- android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache)
- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache)
 Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.  
If this is an unexpected error you can also try to build the project, then manually refresh the layout.  E
xception Details java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener

所以我读到它可能与 appcompat 版本有关,我看到我的 build.gradle 文件中有一个版本,如下所示: 实现'com.android.support:appcompat-v7:28.0.0-alpha3'

我应该查看我的 sdk 文件夹中的 appcompat-v7 文件夹,看看我在那里拥有的最高版本。 -It's version 26.0.0-alpha1

那么解决方案是在我的 SDK 目录中的 appcompat-v7 文件夹中放置一个带有 28.0.0-alpha3 的文件夹吗?那我从哪里得到呢?

如果我了解这里的问题,谁能告诉我...

构建应用程序的 build.gradle 文件中的 appcompat 版本与 SDK 用于在布局编辑器中显示应用程序的版本不同?

谢谢

【问题讨论】:

    标签: android sdk layout-editor android-appcompat


    【解决方案1】:

    在你的Gradle Module: App

    android {
        compileSdkVersion 23
        buildToolsVersion '25.0.0'
        defaultConfig {
            applicationId "com.example.zumoappname"
            minSdkVersion 19
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
    
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.1.2'
    

    你会看到类似的东西,compileSdkVersion 23 的数字必须与 'com.android.support:appcompat-v7:23.4.0' 的数字对应,所以你可以在这个例子中看到我使用 23

    【讨论】:

    • 这两个地方都说 28。奇怪的是,我刚刚将编辑器中的主题从 AppTheme 更改为 DeviceDefault,瞧——它现在可以工作了!知道为什么会这样吗?
    • 这可能是由于不兼容问题我确定
    猜你喜欢
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    相关资源
    最近更新 更多