I understand you want to identify touch events on your ViewPager
, so that you can trigger an animation that hides your ActionBar
. One method requires you create your own subclass of ViewPager
and override onInterceptTouchEvent
:
public class ABetterViewPager extends ViewPager {
public ABetterViewPager(Context context) {
super(context);
}
public ABetterViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
//Enter the code here to communicate a touch event
return super.onInterceptTouchEvent(ev);
}
}
You will probably need to tailor the above to your specifications. For instance, you may only want to trigger the event once someone starts to move their finger on the screen, in which case you would use:
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
//User is moving their finger over the screen
}
In respect to communicating the touch event from your ViewPager
to wherever it needs to be to fire your ActionBar
hiding animation (which I assume is the Activity
hosting the ViewPager
) then you can use an interface
/EventBus
.
Also, don't forget to replace the ViewPager
in your xml
layout
file with the full name of your custom class (i.e. com.example.mywidgets.ABetterViewPager
, or whatever)