在 android 工作室中加载 AppCompat ActionBar 时出现未知错误

下面是我的 xml 文件。在预览中有两个错误“未能加载未知错误的 AppCompat ActionBar”和“未能实例化多个类”。如何能够运行应用程序。但应用程序崩溃了,在 Logcat 没有显示错误。

这是我的预览截图enter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">




<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="506dp" />


<LinearLayout
android:id="@+id/layout_main"
android:orientation="vertical"
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"
android:weightSum="1"
tools:context=".Activity.MainActivity">




<LinearLayout
android:id="@+id/main_layout"
android:orientation="vertical"
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"
android:layout_weight="0.7"
tools:context=".Activity.MainActivity">


<!-- our tablayout to display tabs  -->
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorBlack"
app:tabTextColor="@color/colorWhite"
android:background="@color/colorOran"
android:minHeight="?attr/actionBarSize"
/>


<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


</LinearLayout>


<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:orientation="horizontal"
android:layout_weight="0.3"
android:weightSum="4"
tools:layout_editor_absoluteX="8dp"
android:layout_marginBottom="8dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">


<ImageView
android:id="@+id/btn_home"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ta_home_icon"
android:background="@color/colorOran"
android:layout_marginRight="1dp"
android:scaleType="fitCenter"/>


<ImageView
android:id="@+id/btn_new"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ta_todaydeals_icon"
android:background="@color/colorOran"
android:layout_marginRight="1dp"
android:scaleType="fitCenter"/>


<ImageView
android:id="@+id/btn_fav"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ta_fav_icon"
android:background="@color/colorOran"
android:layout_marginRight="1dp"
android:scaleType="fitCenter"/>


<ImageView
android:id="@+id/btn_auth"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/ta_franchie_icon"
android:background="@color/colorOran"
android:scaleType="fitCenter"
android:layout_marginRight="1dp"
/>


</LinearLayout>


</LinearLayout>




<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />




</android.support.v4.widget.DrawerLayout>

下面是 appbar _ main

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="com.jeyashri.kitchen.jeyashriskitchen.Activity.MainActivity">


<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">




<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorOran"
app:popupTheme="@style/AppTheme.PopupOverlay">


<ImageView
android:id="@+id/app_logo"
android:layout_width="80dp"
android:layout_height="match_parent"
android:src="@drawable/img"/>


<ImageView
android:id="@+id/btn_social"
android:layout_width="75dp"
android:layout_height="35dp"
android:layout_marginRight="1dp"
android:src="@drawable/share_icon" />


</android.support.v7.widget.Toolbar>


</android.support.design.widget.AppBarLayout>


<include layout="@layout/content_main" />




</android.support.design.widget.CoordinatorLayout>
185516 次浏览

这个问题的解决方案取决于你使用的 Android 支持库的版本:

支持库 26.0.0-beta2

这个 android 支持库版本有一个导致上述问题的 bug

在你的 Gradle 构建文件中使用:

compile 'com.android.support:appcompat-v7:26.0.0'

与:

buildToolsVersion '26.0.0'

还有

classpath 'com.android.tools.build:gradle:3.0.0-alpha8'

一切都会好起来的。


图书馆版本28(测试版)

这些新版本似乎又遇到了类似的困难。

res/values/styles.xml中修改 AppTheme样式

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

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

(注意增加的 Base.)

或者降低图书馆的等级,直到问题得到解决:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

在 android 3.0.0中,金丝雀6必须将所有2.6.0 beta2改为 beta1(appcompat、 design、 support Vector)

试试这个:

只要改变:

compile 'com.android.support:appcompat-v7:26.0.0-beta2'

致:

compile 'com.android.support:appcompat-v7:26.0.0-beta1'

参考文献

用这个:

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support:design:26.0.0-beta1'

而不是

implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
implementation 'com.android.support:design:26.0.0-beta2'

在我的例子中,它消除了渲染问题。

打开预览模式

点击下面的链接来解决这个问题

修复呈现问题找不到以下类: android.support. v7.Internal

选择全息主题-> 刷新

Https://www.youtube.com/watch?v=4mxbnwpcuja

在这个网站上找到的,对我有用。 修改/res/values/styles.xml:

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

致:

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

2018年6月通过使用不同的应用程序版本修复问题。 对项目依赖项使用这些代码..。

在 build.gradle (Module: app)中添加这个依赖项

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

快乐编码... :)

这是解决问题的最小配置。

用途:

dependencies {
...
implementation 'com.android.support:appcompat-v7:26.1.0'
...
}

与:

 compileSdkVersion 26
buildToolsVersion "26.0.1"

以及位于项目根目录中的 build.gradle 文件:

buildscript {
...
....
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
...
...
}
}

我在 Style.xml 中做了以下修改

更改以下密码:

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

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

我也面临着同样的问题。没有什么比从布局预览窗口改变主题更能帮助我了。

帮助我把这个加入到 styles.xmlApptheme中:

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
}

但是它还是给了我一个错误: “无法解析符号小部件... 坐标布局”。然后我更新了我的 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

我也有这个问题与 implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'

对我来说,解决方案是按 File-> Invalidate Caches / Restart-> Invalidate-> Close Project-> 从项目窗口删除项目-> Open Project(从项目窗口)。

方法一:

定位 /res/values/styles.xml

改变

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

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

方法二:

修改模板文件(位置: android-studio/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/res/values/styles.xml.ftl)

改变

backwardsCompatibility!true>Theme.AppCompat<#else><#if

backwardsCompatibility!true>Base.Theme.AppCompat<#else><#if

在 YouTube 上观看解决方案

Solution

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

它修复了我在 Android Studio 3.1.3中的红色标记

我也有这个问题,它的解决方法是 将行从 < strong > res/values/styles.xml 更改为

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

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

两种方法都奏效了

Android Studio 3.1.3中也遇到了同样的问题

打开 < em > style.xml 文件

并替换主题名称

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

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

然后 干净重建的项目。这将解决错误。