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

时间:2018-06-10 08:32:31

标签: 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>

这很简单,只需要将 Hello World 打印到布局,但它无法显示。错误如下: Preview error

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

3 个答案:

答案 0 :(得分:5)

我最近遇到了同样的问题,尽管它是一个简单的向导项目。

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

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

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

只需修改为com.android.support:appcompat-v7:27.1.1

答案 1 :(得分:5)

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

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Render error in Android Studio 3.0 Layout Editor

答案 2 :(得分:0)

一切都很好;只需清理项目并再次运行它。

清洁项目选项位于Build。