无法在Android studio中加载具有未知错误的AppCompat ActionBar

Siv*_*iva 151 android android-actionbar

下面是我的xml文件.在预览中有两个错误"无法加载具有未知错误的AppCompat ActionBar"和"无法实现多个类".怎么能运行app.But应用程序崩溃,在Logcat中没有显示错误.

这是我的预览屏幕截图在此输入图像描述

<?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>
Run Code Online (Sandbox Code Playgroud)

以下是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>
Run Code Online (Sandbox Code Playgroud)

小智 321

此问题的解决方案取决于您正在使用的Android支持库的版本:

支持库 26.0.0-beta2

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

在Gradle构建文件中使用:

compile 'com.android.support:appcompat-v7:26.0.0'
Run Code Online (Sandbox Code Playgroud)

有:

buildToolsVersion '26.0.0' 
Run Code Online (Sandbox Code Playgroud)

classpath 'com.android.tools.build:gradle:3.0.0-alpha8'
Run Code Online (Sandbox Code Playgroud)

一切都应该现在正常.


图书馆版本28(测试版)

这些新版本似乎再次遇到类似的困难.

在你res/values/styles.xml修改AppTheme样式

<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)

(注意添加Base.)

或者降级库,直到问题得到解决:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!做到了.BTW对我们来说Android dev newbiew说我应该在build.gradle(Module:app)文件上执行更改 (23认同)
  • 只是好奇:怎么去搞这样的事情呢?我永远不会猜到...... (7认同)
  • 谢谢,但为什么这个错误仍然存​​在于2018年?对于Android新手,由于这个bug,我无法创建"Hello World"项目. (3认同)
  • 我刚开始今天.我遇到过这个问题.这个答案要求编译一些东西,我不知道,因为它没有解释如何做到这一点.但tanchap的答案解决了问题.他/她清楚地解释了该怎么做.这是一个像我一样新鲜的简单任务.所以我认为这应该是答案. (2认同)

小智 275

在这个网站上发现它,它适用于我.修改/res/values/styles.xml来自:

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

至:

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

  • 你能补充说明为何有效吗?它将帮助将来重新审视这一点的人们. (21认同)
  • 2018年3月1日证实了我的问题. (13认同)
  • 这对我也有用.有谁知道为什么这是必要的呢?我已经离开Android几年了,我无法相信我必须做多少努力才能让一个简单的项目启动和运行.(这包括尝试构建/运行Android Studio提供的一些示例项目.) (4认同)
  • 2018年6月30日,这对我有用. (4认同)
  • 2018年7月16日,我也使用'com.android.support:appcompat-v7:28.0.0-alpha3'. (2认同)

Abh*_*hek 26

2018年6月通过使用不同的appcompact版本修复了问题.将这些代码用于您的项目依赖项......

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

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Run Code Online (Sandbox Code Playgroud)

快乐的编码...... :)

  • 它在beta中再次被打破:( (4认同)

she*_*hub 17

方法1:

定位 /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)

方法2:

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

更改

backwardsCompatibility!true>Theme.AppCompat<#else><#if
Run Code Online (Sandbox Code Playgroud)

backwardsCompatibility!true>Base.Theme.AppCompat<#else><#if
Run Code Online (Sandbox Code Playgroud)

在YouTube上观看解决方案

解


Muh*_*zam 17

我也遇到了这个问题,它已经从res/values/styles.xml中作为更改行解决了

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

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

这两种方案都有效


小智 6

打开预览模式

请按照以下链接解决问题

修复 - 呈现问题无法找到以下类:android.support.v7.internal

转到appTheme ---->选择Holo主题--->刷新

https://www.youtube.com/watch?v=4MxBnwpcUjA


Md *_*san 6

Android Studio 3.1.3 中遇到同样的问题

只需转到style.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)

然后清理重建项目。这将解决错误。


V.Y*_*.Y. 5

尝试这个:

只是改变:

compile 'com.android.support:appcompat-v7:26.0.0-beta2'
Run Code Online (Sandbox Code Playgroud)

到:

compile 'com.android.support:appcompat-v7:26.0.0-beta1'
Run Code Online (Sandbox Code Playgroud)

参考


小智 5

替换 implementation 'com.android.support:appcompat-v7:28.0.0-beta01'

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1' 
Run Code Online (Sandbox Code Playgroud)

在build.gradle中(模块:app).它在Android Studio 3.1.3中修复了我的红色标记