下面是我的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>

推荐答案

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

Support library 26.0.0-beta2

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

在Gradle构建文件中使用:

compile 'com.和roid.support:appcompat-v7:26.0.0'

与:

buildToolsVersion '26.0.0' 

classpath 'com.和roid.到ols.build:gradle:3.0.0-alpha8'

现在一切都应该很正常了.


Library version 28 (beta)

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

在您的res/values/styles.xml中,修改AppTheme样式

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

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

(note the added 100)

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

implementation 'com.和roid.support:appcompat-v7:28.0.0-alpha1'

Android相关问答推荐

未解析的引用:背景 colored颜色

无法理解Kotlin Coroutines and Flows中的J.C.编程行为

将Any强制转换为Integer将从API返回NullPointerException

Android意图过滤器不限制应用程序仅处理YouTube链接

使用Kotlin/Compose与Java/XML指南的比较

登录方法显示为空列表,即使它显示的是Firebase身份验证控制台

默认调度程序是否在协程中使用共享线程池?

制作圆形SupportMapFragment

kotlin中&&和and的区别

如何在jetpack compose中使可组合的屏幕zoom 到不同的手机(屏幕)尺寸?

如何在 Jetpack Compose 中对数据类进行 Parcelize

如何添加到先前预填充的 Room 数据库?

在 theme.xml 中使用 android:autoCompleteTextViewStyle

Android:appcompat 和 material 如何从默认创建 appcompat 和 material 视图?

将房间中的实体更新为 isCompleted 并使用 Flow 问题获取所有数据

Android Compose:LazyColumn 和 Column with verticalScroll 的区别

Jetpack 组合和片段

如何将新的 ComponentActivity 与 ViewBinding 和其他旧的 AppCompatActivity 组件一起使用

Delphi 11:以编程方式查找 MSBuild 的正确工具版本

compose FontFamily 错误:必须初始化变量