此次活动由窗口装饰提供的操作栏 [英] This Activity has an action bar supplied by the window decor

查看:280
本文介绍了此次活动由窗口装饰提供的操作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

该活动已经由窗口装饰提供一个操作栏。不要求Window.FEATURE_ACTION_BAR并设置windowActionBar为false,在主题使用工具栏来代替。

MainAcitvity.java:

 公共类MainActivity扩展ActionBarActivity {}

MainActivity.xml:

\r
\r

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com / APK / RES / Android的\r
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s\r
    机器人:layout_width =match_parent\r
    机器人:layout_height =match_parent\r
    工具:上下文=。MainActivity\r
    机器人:方向=垂直\r
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto>\r
\r
    < android.support.v7.widget.Toolbar\r
        机器人:ID =@ + ID /工具栏\r
        机器人:layout_width =match_parent\r
        机器人:layout_height =40dp\r
        机器人:背景=@彩色/初级\r
        应用:主题=@风格/ ToolbarTheme\r
        应用:popupTheme =@风格/ Theme.AppCompat/>\r
\r
    < android.support.v4.widget.DrawerLayout\r
        机器人:ID =@ + ID / drawer_layout\r
        机器人:layout_width =match_parent\r
        机器人:layout_height =match_parent>\r
        <的FrameLayout\r
            机器人:ID =@ + ID / content_frame\r
            机器人:layout_width =match_parent\r
            机器人:layout_height =match_parent/>\r
        < ListView控件\r
            机器人:ID =@ + ID / left_drawer\r
            机器人:背景=@机器人:彩色/白\r
            机器人:layout_width =305dp\r
            机器人:layout_height =match_parent\r
            机器人:layout_gravity =开始/>\r
    < /android.support.v4.widget.DrawerLayout>\r
\r
\r
    < / LinearLayout中>

\r

\r
\r

styles.xml:

\r
\r

<资源的xmlns:机器人=htt​​p://schemas.android.com / APK / RES / Android的>\r
\r
    <样式名称=AppTheme.Base父=Theme.AppCompat.Light>\r
        <项目名称=colorPrimary> @彩色/初级与LT; /项目>\r
        <项目名称=colorPrimaryDark> @彩色/ primaryDark< /项目>\r
        <项目名称=机器人:windowNoTitle>真< /项目>\r
        <项目名称=机器人:windowActionBar>假LT; /项目>\r
    < /风格>\r
\r
    <样式名称=AppTheme父=AppTheme.Base>\r
\r
    < /风格>\r
\r
    <样式名称=ToolbarTheme父=Theme.AppCompat>\r
        <项目名称=机器人:textColorPrimary> @彩色/ abc_primary_text_material_dark< /项目>\r
        <项目名称=actionMenuTextColor> @彩色/ abc_primary_text_material_dark< /项目>\r
        <项目名称=机器人:textColorSecondary> @彩色/ abc_secondary_text_material_dark< /项目>\r
    < /风格>\r
\r
    < /资源>

\r

\r
\r

然后在OnCreate()中我有:

\r
\r

工具栏=(栏)findViewById(R.id.toolbar);\r
    ...\r
    setSupportActionBar(工具栏);\r
getSupportActionBar()setDisplayHomeAsUpEnabled(真)。\r
getSupportActionBar()setHomeButtonEnabled(真)。\r
\r
mDrawerToggle =新ActionBarDrawerToggle(这一点,mDrawerLayout,工具栏,\r
R.string.drawer_open,R.string.drawer_close){\r
公共无效onDrawerClosed(查看视图){\r
。getActionBar()的setTitle(mTitle);\r
invalidateOptionsMenu();\r
}\r
\r
公共无效onDrawerOpened(查看drawerView){\r
getActionBar()的setTitle(mDrawerTitle);`输入code here`\r
invalidateOptionsMenu();\r
}\r
};\r
\r
mDrawerLayout.setDrawerListener(mDrawerToggle);

\r

\r
\r


解决方案

编辑风格的XML和覆盖或替换Theme.AppCompat.Light.NoActionbar
在地方当前正在使用什么。

I have a problem with my custom Navigation Drawer. When I compile my application the following error messages :

This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.

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>

Then in OnCreate() I have :

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);

解决方案

Edit your style XML and override or replace "Theme.AppCompat.Light.NoActionbar" In place of what you are currently using.

这篇关于此次活动由窗口装饰提供的操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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