title: How to replace deprecated android.support.v4.app.ActionBarDrawerToggle
body: <p>Yesterday (17-10-2014) I have update Android SDK and <code>support-library-v4.jar</code> of my App, now I get deprecation warning related to <code>ActionBarDrawerToggle</code>, reading <a href="https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html" rel="noreferrer">the documentation</a> seems that I have to use the <code>ActionBarDrawerToggle</code> in <code>support-library-v7.appcompact.jar</code>.</p>
  
  <p>Here some parts of my Activity that could be relevants:</p>
  
  <pre><code>import android.app.ActionBar;
  import android.app.Activity;
  import android.content.res.Configuration;
  import android.os.Bundle;
  import android.support.v4.app.ActionBarDrawerToggle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.webkit.WebView;
  import android.widget.LinearLayout;
  import android.widget.ListView;
  import android.widget.RelativeLayout;
  import android.widget.TextView;
  
  
  public class MyActivity extends FragmentActivity {
      private ActionBar bar;
      private CustomActionBarDrawerToggle mDrawerToggle;
      private DrawerLayout mDrawer;
      private ListView mDrawerList;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_infoviewer);
  
          bar = this.getActionBar();
  
          bar.setDisplayHomeAsUpEnabled(true);
  
          bar.setHomeButtonEnabled(true);
          bar.setDisplayShowTitleEnabled(false);
          mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  
          mDrawer.setBackgroundColor(getResources().getColor(R.color.White));
          initNavMenu();
          try {
              mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
          } catch (RuntimeException e) {
              e.printStackTrace();
          }
  
          mDrawer.setDrawerListener(mDrawerToggle);
      }
  
      ....
  
      private void initNavMenu() {
          NavMenuAdapter mAdapter = MyDrawers.getDefaultDrawer(MyActivity.this, true);
          mDrawerList = (ListView) findViewById(R.id.drawer);
          mDrawerList.setBackgroundColor(getResources().getColor(R.color.GreenMoneyDark));
          if (mDrawerList != null) mDrawerList.setAdapter(mAdapter);
          mDrawerList.setOnItemClickListener(new DrawerItemClickListener(MyActivity.this, mDrawer, mDrawerList));
      }
  
      @Override
      protected void onPostCreate(Bundle savedInstanceState) {
          super.onPostCreate(savedInstanceState);
          // Sync the toggle state after onRestoreInstanceState has occurred.
          mDrawerToggle.syncState();
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          mDrawerToggle.onConfigurationChanged(newConfig);
      }
  
      private class CustomActionBarDrawerToggle extends ActionBarDrawerToggle {
  
          public CustomActionBarDrawerToggle(Activity mActivity,
                                             DrawerLayout mDrawerLayout) {
              super(mActivity, mDrawerLayout, R.drawable.action_drawer,
                      R.string.ns_menu_open, R.string.ns_menu_close);
          }
  
          @Override
          public void onDrawerClosed(View view) {
              bar.setTitle(getString(R.string.ns_menu_close));
              invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
  
          @Override
          public void onDrawerOpened(View drawerView) {
              bar.setTitle(getString(R.string.ns_menu_open));
              invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
      }
  
  }
  </code></pre>
  
  <p>I have tried to copy support-library-v7 and replace </p>
  
  <pre><code>import android.support.v4.app.ActionBarDrawerToggle;
  </code></pre>
  
  <p>with</p>
  
  <pre><code> import android.support.v7.app.ActionBarDrawerToggle;
  </code></pre>
  
  <p>this has caused compilation problem in </p>
  
  <pre><code> public CustomActionBarDrawerToggle(Activity mActivity,
                                                 DrawerLayout mDrawerLayout) {
                  super(mActivity, mDrawerLayout, R.drawable.action_drawer,
                          R.string.ns_menu_open, R.string.ns_menu_close);
              }
  </code></pre>
  
  <p>So I have tried to replace <code>R.drawable.action_drawer</code> with </p>
  
  <pre><code>public CustomActionBarDrawerToggle(Activity mActivity,
                                             DrawerLayout mDrawerLayout) {
              super(mActivity, mDrawerLayout,new Toolbar(MyActivity.this) ,
                      R.string.ns_menu_open, R.string.ns_menu_close);
          }
  </code></pre>
  
  <p>this compiles but crash at Runtime with </p>
  
  <pre><code> java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$attr;
              at android.support.v7.widget.Toolbar.&lt;init&gt;(Toolbar.java:190)
              at android.support.v7.widget.Toolbar.&lt;init&gt;(Toolbar.java:186)
  </code></pre>
  
  <p>Note that <code>android-support-v7-appcompat.jar</code> is correctly added in project dependencies
  <img src="https://i.stack.imgur.com/XdDx1.jpg" alt="enter image description here"></p>