无法在 android studio 中加载 AppCompat ActionBar 并出现未知错误 [英] Failed to load AppCompat ActionBar with unknown error in android studio

查看:34
本文介绍了无法在 android studio 中加载 AppCompat ActionBar 并出现未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的 xml 文件.在预览中有两个错误'Failed to load AppCompat ActionBar with unknown error' &'未能实例化多个类'.如何能够运行应用程序.但是应用程序崩溃并且在 Logcat 中没有显示任何错误.

Below is my xml file. In preview there is two error'Failed to load AppCompat ActionBar with unknown error' & 'Failed to instaniate more than one class'. How ever am able to run the app.But the app crashes and in Logcat no errors are shown.

这是我的预览屏幕截图

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

Below is 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>

推荐答案

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

The solution to this problem depends on the version of the Android support library you're using:

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

This android support library version has a bug causing the mentioned problem

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

In your Gradle build file use:

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

与:

buildToolsVersion '26.0.0' 

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

现在一切正常.

这些新版本似乎又遇到了类似的问题.

These new versions seem to suffer from similar difficulties again.

在你的 res/values/styles.xml 中修改 AppTheme 样式来自

In your res/values/styles.xml modify the AppTheme style from

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

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

(注意添加的Base.)

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

Or alternatively downgrade the library until the problem is fixed:

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

这篇关于无法在 android studio 中加载 AppCompat ActionBar 并出现未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆