WebView does not support OnClickListener . It also consumes touch events, even if nothing happened on the webpage, so ancestor views (like your LinearLayout ) cannot create an OnClick event. This is very unfortunate.
As a workaround, I extended the RelativeLayout and placed its WebView inside it. In RelativeLayout I onInterceptTouchEvent and looked for tap events. If an answer is found, then RelativeLayout OnClickListener is called using performClick() .
public class TapAwareRelativeLayout extends RelativeLayout { private final float MOVE_THRESHOLD_DP = 20 * getResources().getDisplayMetrics().density; private boolean mMoveOccured; private float mDownPosX; private float mDownPosY; public TapAwareRelativeLayout(Context context) { super(context); } public TapAwareRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mMoveOccured = false; mDownPosX = ev.getX(); mDownPosY = ev.getY(); break; case MotionEvent.ACTION_UP: if (!mMoveOccured) {
}
Zsolt Safrany Jan 30 2018-12-12T00: 00Z
source share