0

So in my app I have a section where a new Activity is started that contains a ViewPager / Navigation Drawer, the thing where you click the hamburger icon and a little pane slides out from the left so you have another place to click menu options.

However the button that causes this to slide out is the hamburger icon where normally the back arrow exists.

Is there a known way to get around this? I don't know if there is a feature that allows both a back arrow AND a hamburger/drawer-expansion icon on the screen at the same time in some form.

KaliMa
  • 1,970
  • 6
  • 26
  • 51

1 Answers1

0

Normally you don't need to have a back arrow or button since Android has a back button built in with OS, which is also easy for users.

If you don't know how to handle it when Navigation Drawer is open, Here is the code.

@Override
public void onBackPressed() {
    if (isNavDrawerOpen()) {
        closeNavDrawer();
    } else {
        super.onBackPressed();
    }
}

Back arrow can't be placed along with hamburger icon in the toolbar. So, if you want back button in the UI, create a button and place it in the bottom. set OnClickListener and call onBackPressed() method inside it.

backButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onBackPressed();
            }
    });
Raviraj Subramanian
  • 364
  • 1
  • 6
  • 11