无法加载具有未知错误的AppCompat ActionBar

sya*_*ein 5 android

我的项目无法在预览中呈现布局.我的Android Studio版本3.1.2.我正在使用API​​ 28.这是我的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/frame_container">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Hello World"
    android:gravity="center"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这很简单,只是将Hello World打印到布局,但它无法显示.错误如下: 预览错误

我搜索解决问题,解决方案是使用API​​ 26.我尝试,一切正常,预览成功.但是我创建片段活动,问题又回来了,预览无法显示. 如果您有新的解决方案,请帮助我!

小智 5

我最近遇到了同样的问题,尽管它是一个精灵简单的项目.

我尝试了23级(Mashmallow)没有任何变化.我卸载了Android Studio,重新安装它,它没有做任何更改,错误仍然存​​在...

然后我意识到这个问题来自一个依赖(最近可能是谷歌更新了一个错误).解决方案是使用以前的版本.

转到文件 - >项目结构 - >模块应用程序 - >依赖项选项卡.项目创建期间向导使用的默认值为com.android.support:appcompat-v7:28.0.0-alpha3

简单修改到com.android.support:appcompat- V7:27.1.1

  • 这解决了我.我更改了`build.gradle`并使用了`compileSdkVersion 27`和``implementation'com.android.support:appcompat-v7:27.1.1'`然后使缓存/重启无效. (2认同)

Ata*_*ara 5

在app\res\values\styles.xml中更改

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)

(在Android Studio 3.0布局编辑器中渲染错误)