问题描述
我有一个带有Fragment布局的主Activity.抽屉有3个选项:
I have a main Activity with a Fragment layout. The drawer has 3 option:
Fragment[1], Fragment[2], Fragment[3].
Fragment [2]和Fragment [3]内部是一个按钮.此按钮打开其他片段.片段[4].
Inside Fragment[2] and Fragment[3] is one button. This button open other fragment. Fragment[4].
我希望Fragment [4]不带抽屉,但带有后退按钮.
I want Fragment[4] without drawer but with a back button.
这是Fragment [2]中的onClick代码
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();
在Fragment [4]
And in Fragment[4]
onCreate方法:
onCreate method:
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
但是此解决方案不起作用.
But this solution doesn't work.
如何禁用抽屉?我应该在哪里安装后退按钮?在Fragment [2]或Fragment [3]中?
How to disable the drawer? Where should I implement the back button? In Fragment[2] or Fragment[3]?
推荐答案
-
您可以使用:
You can use :
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
这将锁定抽屉在swipe
添加行
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
在活动"中,它使所有片段都像片段1、2、3和4.可能是您的情况,片段4与片段2来自不同的活动.因此,按后退按钮不起作用
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
这篇关于如何禁用片段中的抽屉并返回正确的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!