dimanche 3 mai 2015

This Activity has an action bar supplied by the window decor

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://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    xmlns:app="http://ift.tt/GEGVYd">

    <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://ift.tt/nIICcg">

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

Aucun commentaire:

Enregistrer un commentaire