【问题标题】:Activity already has an action bar supplied by the window decorActivity 已经有一个由窗口装饰提供的操作栏
【发布时间】:2017-11-09 00:28:42
【问题描述】:

完全错误:

这个 Activity 已经有一个由窗口装饰提供的操作栏。 不要请求 Window.FEATURE_SUPPORT_ACTION_BAR 并设置 在您的主题中将 windowActionBar 设置为 false 以使用工具栏。

我知道这是因为我有一个带有操作栏的活动,然后我正在尝试添加一个新活动。但我不确定默认操作栏在哪里......

它不喜欢的代码是这里的第二行:

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

activity_main.xml

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="com.example.apple.bookshelf.MainActivity">

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

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

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

        <ListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/authors_list_view" />

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

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/menu_navigation"/>

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

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColor">@android:color/black</item>
    </style>

    <style name="AppTheme.NoActionBar" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

【问题讨论】:

  • 我希望你没有在活动清单中使用 AppTheme,它已经有 DarkActionBar 作为工具栏。

标签: android


【解决方案1】:

解决方案:

我要做的就是改变

<activity android:name=".MainActivity" >

<activity android:name=".MainActivity" android:theme="@style/AppTheme.NoActionBar" >

AndroidManifest.xml

【讨论】:

    猜你喜欢
    • 2016-05-16
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多