0

I found out, that I can turn on the back arrow with

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

but when I click on the arrow the drawer opens instead of going to the first Fragment.

How can I turn off the AppDrawer inside a Fragment and turning it on again when in first Fragment?

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • I found my answer here: http://stackoverflow.com/questions/17258020/switching-between-android-navigation-drawer-image-and-up-caret-when-using-fragme?rq=1 – Guido Steiner Mar 16 '16 at 14:14

1 Answers1

1

With the following lines of code when you back press first time then if your drawer opened then first it will close then on second back press you will go on previous activity.

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {//this is check drower is open or not
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();//or you can redirect to the another activity
    }
}
Bhunnu Baba
  • 1,742
  • 15
  • 22
Nandkishor mewara
  • 2,552
  • 16
  • 29
  • Thanks for this solution, but it's not quite what i had in mind. Beside I'm not sure if a user would sense this behavier. Isn't there a way to turn of the Drawer while on a specifiy Fragment? – Guido Steiner Mar 16 '16 at 14:01