当前位置: 首页 > 知识库问答 >
问题:

无法在android studio中加载AppCompat ActionBar,出现未知错误

仲浩歌
2023-03-14

下面是我的xml文件。预览中出现两个错误“加载AppCompat ActionBar失败,错误未知”

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

共有3个答案

公西鸿博
2023-03-14

通过使用不同的appcompact版本修复了2018年6月的问题。在项目依赖项上使用这些代码。。。

内置的。gradle(模块:应用程序)添加此依赖项

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

快乐编码…:)

宗政子辰
2023-03-14

在这个网站上找到的,对我有用。修改/res/值/样式。xml来自:

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

到:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
</style>
宫弘亮
2023-03-14

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

此android支持库版本存在导致上述问题的错误

在Gradle构建文件中使用:

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

与:

buildToolsVersion '26.0.0' 

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

现在一切都应该正常了。

这些新版本似乎又遭遇了类似的困境。

res/值/样式中。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'
 类似资料:
  • 问题内容: 当我尝试使用Terminal中的命令使用python创建虚拟环境时,出现以下错误: 我不是第一个遇到类似错误的人-我尝试遵循此答案的建议并运行: 那没有帮助。也没有以超级用户身份运行commmand。 接下来我应该调查什么? 问题答案: 我有完全相同的错误消息。Continuum Analytics支持小组的Ray Donnelly提供了以下解决方案,为我解决了这个问题: 当您pip安

  • 我有下面的代码,在这里我尝试将值插入到2个字符串的multimap中,但是我不断得到一个我无法理解的错误。我已经想解决这件事好几个小时了。 该程序的全部要点是基于多映射插入的自动排序对字典的行进行排序。 我不断得到的错误是:

  • 问题内容: 我已刷新我的应用程序页面,并在控制台中收到此错误 。 我试图重新安装XAMPP版本,但这对我不起作用。 问题答案: 我认为您正在使用Chrome。问题是证书不匹配或证书过期。请正确检查证书。

  • 我一直试图使用Selenium sendkeys(),但没有成功使用Chrome。我在这里研究过类似的问题,但似乎没有成功。我可以生成URL,调用按钮(click()),但是当我试图在特定的文本字段中输入值时,我会得到: 线程“main”org.openqa.selenium.WebDriverException中出现异常:未知错误:无法聚焦元素。

  • 我在一个网站上加载jQuery时遇到了一个问题,我在自己的供应商文件中使用了一个缩小版,在控制台中出现了这个语法错误: 这个站点上有一个旧版本的JQuery,我不能删除它,在加载供应商库和JS之前,我在HTML文件的顶部放了一个noconflict。有什么想法吗? 提前致谢:)

  • 我似乎无法将任何数据从Socrata上传到BigQuery。我得到“加载操作中出现BigQuery错误:无法连接BigQuery服务器。”最初,我得到的错误限制为0个错误。现在,我已将CSV文件限制为一个数据行,因此出现了连接错误。下面是我的日志输出、代码和CSV。 我的日志输出: 我的代码: 我的csv文件: