public class MainActivity extends ActionBarActivity {
private String[] drawerListItems;
private ListView drawerListView;
private DrawerLayout drawerlayout;
private ActionBarDrawerToggle drawToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerlayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerListItems = getResources().getStringArray(R.array.DrawreMenue);
drawerListView = (ListView) findViewById(R.id.slidermenu);
Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
//getActionBar().setIcon(R.drawable.ic_launcher);
drawerListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, drawerListItems));
//drawerListView.setOnItemClickListener(this);
drawerListView.setOnItemClickListener(new DrawerItemClickListener());
drawToggle = new ActionBarDrawerToggle(this, drawerlayout,toolbar,
R.string.draw_open,
R.string.draw_close
) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
} ;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_drawer);
drawerlayout.setDrawerListener(drawToggle);
drawToggle.syncState();
}
I am Using this code in Android Studio
minSdkVersion 8
targetSdkVersion 21
It is showing Drawer Icon but on-click it not opening Drawer List and not Closing it when it opened by sliding
first of all you need to find id of the Button that you want to click to open Drawer then just put code in click listener to open
and to close drawer put