Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add callback on home button is pressed? #49

Open
yhojann-cl opened this issue Oct 4, 2015 · 1 comment
Open

How to add callback on home button is pressed? #49

yhojann-cl opened this issue Oct 4, 2015 · 1 comment

Comments

@yhojann-cl
Copy link

Try change home button with mNavigationDrawerFragment.showBackButton() for back to previous fragment but how to trigger on button is pressed and prevent open drawer? onOptionsItemSelected(MenuItem item) does not work.

@yhojann-cl
Copy link
Author

By using "showBackButton ()" to change the navigation button on the menu and still calling does not work as it should and the back button.

Solution for me, to navigate between fragments:

public void showBackButton() {
    if (getActivity() instanceof ActionBarActivity) {
        ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    //Disables onClick toggle listener (onClick)
    mActionBarDrawerToggle.setDrawerIndicatorEnabled(false);
    mActionBarDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (mOnBackPressed != null)
                    mOnBackPressed.call();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    });

    mToolbar.setNavigationIcon(((ActionBarActivity)getActivity()).getV7DrawerToggleDelegate().getThemeUpIndicator());
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}

mOnBackPressed is Callable:

public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar){
     this.setup(fragmentId, drawerLayout, toolbar, null);
}

public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar, @Nullable Callable onBackPressed) {
        mToolbar = toolbar;
        mOnBackPressed = onBackPressed;
        ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant