How to Disable drawer in fragment and back back to correct fragment

拜拜、爱过 提交于 2019-12-21 12:43:28

问题


I have a main Activity with a Fragment layout. The drawer has 3 option:

Fragment[1], Fragment[2], Fragment[3].

Inside Fragment[2] and Fragment[3] is one button. This button open other fragment. Fragment[4].

I want Fragment[4] without drawer but with a back button.

This is the onClick code in Fragment[2]

Fragment fragment = new InstalacionesEncontradasFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("key", this.instalacionesConCategorias);
fragment.setArguments(bundle);
FragmentManager fragmentManager = getFragmentManager();

FragmentTransaction mFragmentTransaction = fragmentManager.beginTransaction();
mFragmentTransaction.addToBackStack(null);
mFragmentTransaction.replace(R.id.main_frame_container, fragment, "ACTIVIDADES").commit();

And in Fragment[4]

onCreate method:

getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);

But this solution doesn't work.

How to disable the drawer? Where should I implement the back button? In Fragment[2] or Fragment[3]?


回答1:


  1. You can use :

    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    

    This will lock drawer opening on swipe

  2. Add the line

    getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
    

in Activity which makes all fragments like Fragment 1, 2,3 and 4. May be in your case, Fragment 4 is from differenct activity than Fragment 2. So, back button press is not working



来源:https://stackoverflow.com/questions/29797075/how-to-disable-drawer-in-fragment-and-back-back-to-correct-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!