mgamer
mgamer

Reputation: 14050

Android disable passing events to underlying webview

I have a TextView displayed on top of a WebView. Both of them are placed inside a RelativeLayout.

Since TextView is displayed on top of a WebView and covers the whole of a WebView I would like to disable passing touch events from TextView to underlying WebView. I don't want touching TextView to cause scrolling in a WebView.

Is that possible in Android? If so, how?

Upvotes: 2

Views: 2079

Answers (1)

Shiki
Shiki

Reputation: 16808

You can attach a View.OnTouchListener on your TextView that returns true to prevent propagating touches to the underlying WebView.

findViewById(R.id.textview).setOnTouchListener(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    // return TRUE since we want to consume the event
    return true; 
  }
});

Note that this will prevent all touches on your WebView: scrolls and clicks.

Upvotes: 6

Related Questions