Hiding/showing the contextual action bar programmatically

我只是一个虾纸丫 提交于 2019-12-04 08:36:58

You need to first add a ViewPager.OnPageChangeListener with ViewPager.OnPageChangeListener to your viewPager.

In the onPageSelected method call a method in your ListFragment to dismiss your CAB.

EDIT:

To get the current active fragment you can use it's tag. The tag can be computated with this method:

private static String makeFragmentName(int viewId, int index) {
   return "android:switcher:" + viewId + ":" + index;
}

where viewId is the id of the viewpager and index the tab index (position)

mtotschnig

You can also react to the fragment being hidden from inside the fragment by using the method setUserVisibleHint, as explained in https://stackoverflow.com/a/11075663/1199911

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