问题描述
我有2个片段 mainFragment
和 childFragment
。我想说明动作条中的 mainFragment
,但要在 childFragment
隐藏。所有工作正常,只是当我回来 mainFragment
从 childFragment
,再次进入 childFragment
操作栏显示前几秒钟让隐藏..
我不知道为什么?帮助
在 childFragment
我这样做
@覆盖
公共无效onResume(){
super.onResume();
((ActionBarActivity)getActivity())getSupportActionBar()隐藏()。
mainActivity.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
。getView()setFocusableInTouchMode(真正的);
。getView()requestFocus的();
getView()。setOnKeyListener(新View.OnKeyListener(){
@覆盖
公共布尔onKey(视图V,INT关键code,KeyEvent的事件){
如果(event.getAction()== KeyEvent.ACTION_UP和放大器;&放大器;关键code == KeyEvent.KEY code_BACK){
//处理后退按钮的点击监听器
mainActivity.onBack pressed();
。((ActionBarActivity)getActivity())getSupportActionBar()显示();
mainActivity.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
返回true;
}
返回false;
}
});
}
尝试做这在你的fragmen的onActivityCreated方式:
((ActionBarActivity)getActivity())getSupportActionBar()隐藏()。
mainActivity.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
编辑:我假设你正在处理您的交易片段,在你的活动。在你替换你的片段活动:
getSupportFragmentManager()的BeginTransaction()代替(R.id.frame_layout,新YourFragment())提交()。;
根据您要更换哪些片段做你的动作条隐藏和显示操作。 (主或子)
I have 2 Fragments mainFragment
and childFragment
. I want to show actionbar in mainFragment
but wants to hide in childFragment
. All is working fine except that when I comes back to mainFragment
from childFragment
and again goes to childFragment
action bar shows for seconds before get hidden ..
I don't know why ?HELP
In childFragment
I am doing this
@Override
public void onResume() {
super.onResume();
((ActionBarActivity) getActivity()).getSupportActionBar().hide();
mainActivity.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
getView().setFocusableInTouchMode(true);
getView().requestFocus();
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
// handle back button's click listener
mainActivity.onBackPressed();
((ActionBarActivity) getActivity()).getSupportActionBar().show();
mainActivity.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
return true;
}
return false;
}
});
}
Try to do this in your fragmen's onActivityCreated method:
((ActionBarActivity) getActivity()).getSupportActionBar().hide();
mainActivity.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Edit:I assume that you are handling your fragment transactions in your activity. Before you replace your fragment in activity with:
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, new YourFragment()).commit();
do your actionbar hide and show operations according to which fragment you are replacing. (main or child)
这篇关于安卓:在片段隐藏行动起来吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!