Reputation: 3232
I have a problem with the NavigationDrawer icon, I want it to be visible within the ActionBar. It is needed to show the user, that he can open the drawer in my app by swiping from the left edge of the screen.
I use this code before without any problems, but in this application it isn't working well, I don't know what the problem can be. Please help me.
Here is my code:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
ArrayList<Integer> smIcon_adrs = new ArrayList<Integer>();
smIcon_adrs.add(R.drawable.sm_font);
smIcon_adrs.add(R.drawable.sm_size);
smIcon_adrs.add(R.drawable.sm_count);
smIcon_adrs.add(R.drawable.sm_about);
ArrayAdapter<Integer> sm_adapter = new smIcoAdapter(getBaseContext(),
smIcon_adrs);
mDrawerList.setAdapter(sm_adapter);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.hello_world, R.string.app_name) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle("دعا عهد");
supportInvalidateOptionsMenu();
super.onDrawerClosed(view);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle("امکانات");
supportInvalidateOptionsMenu();
super.onDrawerOpened(drawerView);
// onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayout.setDrawerListener(mDrawerToggle);
and here:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_play:
if (mp.isPlaying()) {
item.setIcon(R.drawable.actn_play);
mp.pause();
} else {
updateProgressBar();
mp.start();
item.setIcon(R.drawable.actn_stop);
}
break;
}
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
public boolean onPrepareOptionsMenu(Menu menu) {
mDrawerLayout.isDrawerOpen(mDrawerList);
// menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
Upvotes: 1
Views: 485
Reputation: 2153
Here is someone with a similar problem, you might test the solution posted there: https://stackoverflow.com/a/23332975/1738838.
According to that you are missing this method:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
Upvotes: 1