此活动有一个由窗口装饰提供的操作栏

时间:2015-05-03 17:12:27

标签: java android xml android-layout

我的自定义导航抽屉有问题。当我编译我的应用程序时,出现以下错误消息:

此活动已有窗口装饰提供的操作栏。请勿在主题中请求Window.FEATURE_ACTION_BAR并将windowActionBar设置为false以使用工具栏。

MainAcitvity.java:

public class MainActivity extends ActionBarActivity {}

MainActivity.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/primary"
        app:theme="@style/ToolbarTheme"
        app:popupTheme="@style/Theme.AppCompat"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <ListView
            android:id="@+id/left_drawer"
            android:background="@android:color/white"
            android:layout_width="305dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"/>
    </android.support.v4.widget.DrawerLayout>


    </LinearLayout>

styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primaryDark</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
    </style>

    <style name="AppTheme" parent="AppTheme.Base">

    </style>

    <style name="ToolbarTheme" parent="Theme.AppCompat">
        <item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
        <item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
        <item name="android:textColorSecondary">@color/abc_secondary_text_material_dark</item>
    </style>

    </resources>

然后在OnCreate()中我有:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ...
    setSupportActionBar(toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);

		mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
				R.string.drawer_open, R.string.drawer_close) {
			public void onDrawerClosed(View view) {
				getActionBar().setTitle(mTitle);
				invalidateOptionsMenu();
			}

			public void onDrawerOpened(View drawerView) {
				getActionBar().setTitle(mDrawerTitle);`enter code here`
				invalidateOptionsMenu();
			}
		};

		mDrawerLayout.setDrawerListener(mDrawerToggle);

0 个答案:

没有答案