Skip to content

Instantly share code, notes, and snippets.

@akshaydashrath
Created June 7, 2013 06:30
Show Gist options
  • Save akshaydashrath/5727406 to your computer and use it in GitHub Desktop.
Save akshaydashrath/5727406 to your computer and use it in GitHub Desktop.
Support for ActionbarSherlock with the new DrawerLayout
import android.app.Activity;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import com.actionbarsherlock.view.MenuItem;
/**
* Created by akshay on 06/06/2013.
*/
public class ActionBarDrawerToggleCompat extends ActionBarDrawerToggle {
private final DrawerLayout drawerLayout;
private static final int ID_HOME = 0x0102002c;
public ActionBarDrawerToggleCompat(Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes) {
super(activity, drawerLayout, drawerImageRes, openDrawerContentDescRes, closeDrawerContentDescRes);
this.drawerLayout = drawerLayout;
}
public boolean onSupportOptionsItemSelected(MenuItem item) {
if (item != null && item.getItemId() == ID_HOME && isDrawerIndicatorEnabled()) {
if (drawerLayout.isDrawerVisible(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
drawerLayout.openDrawer(GravityCompat.START);
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment