Java code :
@Override
onCreate()
{
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.right_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerLayout.setAlpha((float)0.8);
mDrawerList.setAdapter(adapter);
mDrawerList.setClickable(false);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerToggle = new ActionBarDrawerToggle(this, // host Activity
mDrawerLayout, // DrawerLayout object
R.drawable.ic_drawer, // nav drawer image to replace 'Up' caret
R.string.drawer_open, // "open drawer" description for
// accessibility
R.string.drawer_close // "close drawer" description for
// accessibility
) {
public void onDrawerClosed(View view) {
// getActionBar().setTitle(mTitle);
// invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
// getActionBar().setTitle(mDrawerTitle);
// invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
SubMenu filter = menu.addSubMenu(" ");
subFilter = filter.getItem().setVisible(true);
filter.setIcon(R.drawable.ico_filter);
subFilter.setShowAsAction(android.view.MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content
// view
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
subFilter.setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.equals(subFilter)) {
if (mDrawerLayout.isDrawerOpen(Gravity.END) == true) {
mDrawerLayout.closeDrawers();
} else {
mDrawerLayout.openDrawer(Gravity.END);
}
} else {
onBackPressed();
}
return true;
}