i implemented a contextual action mode bar in a nested fragement. This fragment is part of a view pager and the view pager is also a fragment and part of a navigation drawer.
Here's what worked for me --
public static ActionMode mActionMode;
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mActionMode = mode;
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
}
ViewPager.OnPageChangeListener
in MyViewPagerActivity. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
....
@Override
public void onPageScrollStateChanged(int state) {
if(MyFragment.mActionMode != null) MyFragment.mActionMode.finish();
}
});