Good day. I have a Main Activity , it has a DrawerLayout and 3 fragments. From the 3rd fragment there is a transition to the 4th fragment, in which you want to disable DrawerLayout , remove the "Hamburger button" and make the Back-Arrow button to return to the 3rd. The transition from 3 Fragments to 4 and back is normal, DrawerLayout works, but after switching from 4 to 3, the "Hamburger" button does not work correctly. Whichever fragment is currently loaded, when you click on the "Hamburger" button, it always goes to the 3rd fragment. I just can not figure out where the problem is. It seems to have not appointed her anything like that ..

  mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Отключаю "Гамбургер" кнопку MainActivity.toggle.setDrawerIndicatorEnabled(false); //Создаю транзакцию FragmentTransaction ftrans = getFragmentManager().beginTransaction(); addFilterFrag = new AddFilterFrag(); //Меняю местами, addFilterFrag - 4ый Фрагмент ftrans.replace(R.id.content_frame, addFilterFrag); ftrans.addToBackStack(null); ftrans.commit(); } }); 

There is a transition to the 4th Fragment - addFilterFrag . Here, in the onCreate() method, I disable DrawerLayout :

 MainActivity.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 

And in the onCreateView() method, I call the ToolBar from the MainActivity , make an icon on the toolbar and assign it the transition action back to the 3rd fragment.

  MainActivity.toolbar.setNavigationIcon(R.drawable.back_icon); MainActivity.toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Возобновляю работу "Гамбургер" кнопки: MainActivity.toggle.setDrawerIndicatorEnabled(true); FragmentTransaction ftrans = getFragmentManager().beginTransaction(); filterFrag = new FilterFrag(); ftrans.replace(R.id.content_frame, filterFrag); //Включаю работу DrawerLayout MainActivity.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); ftrans.commit(); }}); 
  • What error and on which line does it crash? This is mandatory information without some help to you is almost impossible. - Yuriy SPb
  • @YriySPb I changed the question, the transitions have earned, but now there is another problem. Look here please. - ivanovd422
  • @YuriSPb seems to be the problem: the "Hamburger button" plays the role of ToolBar a, которого я подключил в 4-ом Фрагменте. Нужно как-то отключить его и возобновить обычную работу Hamburget Button a, которого я подключил в 4-ом Фрагменте. Нужно как-то отключить его и возобновить обычную работу Hamburget Button a - ivanovd422
  • Iknoku and setNavigationOnClickListener do not need to put yourself. SetDrawerIndicatorEnabled is enough. handle clicking on the arrow / hamburger is necessary in onOptionsItemSelected. More in any way - too many nuances. - Yuriy SPb
  • @YuriySPb Yes, the point is that there are too many nuances. I analyzed more than 30 topics on SO, but for some reason nothing works for me even approximately, except for my code (which I wrote above). I tried to call redefine getActivity().onBackPressed and call in fragments, etc. but something doesn’t work .. - ivanovd422

1 answer 1

  toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } });