Open yhojann-cl opened 9 years ago
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;
...
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.