[英]How to show and hide actionbar for fragments using viewpager
I have fragment A, B, C, D inside a viewpager. 我在viewpager中有片段A,B,C,D。 I want to hide the actionbar in fragment A and show the actionbar for the rest of the fragments. 我想隐藏片段A中的操作栏并显示其余片段的操作栏。
Any Ideas? 有任何想法吗? Thanks. 谢谢。
Edit: Tried the following and still had the actionbar show up in all the fragments. 编辑:尝试以下操作,仍然在所有片段中显示操作栏。
@Override
public void onPageSelected(int position) {
if (position == 0) {
mActionBar.hide();
} else {
mActionBar.show();
}
}
Pretty much when you open the activity with the viewpager I am want Fragment A to show up with no actionbar but when i swipe to view the other fragments I want the actionbar to be shown. 当你用viewpager打开活动时,我希望片段A显示没有操作栏,但是当我滑动查看其他片段时,我希望显示操作栏。
In Fragments you want to show the Action Bar : 在片段中,您想要显示操作栏:
@Override
public void onResume() {
super.onResume();
actionBar.show();
}
In Fragments you dont want to show the Action Bar : 在Fragments中你不想显示Action Bar:
@Override
public void onResume() {
super.onResume();
actionBar.hide();
}
For a ViewPager : 对于ViewPager:
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int selectedPage) {
// Check the selectedPage here and then show and
// hide the actionBar accordingly.
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.