0

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);
GJer
  • 85
  • 1
  • 10
  • Please apply theme or style to your activity in manifest file which contains false in its style. – Jay Shah May 03 '15 at 17:14
  • Hello Shah, Thx for answer. But I already have the tag in my manifest file : android:theme="@style/AppTheme" – GJer May 03 '15 at 17:21

1 Answers1

1

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

Priya Singhal
  • 1,261
  • 11
  • 16
  • I changed my style XML but i have a nullPointerException when i compile my application. – GJer May 03 '15 at 18:20
  • I resolve my problem. Just change getActionBar().setTitle(mTitle); for getSupportActionBar().setTitle(mTitle); – GJer May 03 '15 at 19:22