Chaudhary
Chaudhary

Reputation: 93

How to disable touch/click events on webview

My web view is inside a linear layout. I want the linear layout clickable, but the web view inside it click-disabled. I've tried everything, nothing worked for me. This is my main activity code. This is not working.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView browser = (WebView) findViewById(R.id.webview);
        browser.setWebViewClient(new MyBrowser());
        browser.setEnabled(false);

        browser.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(MainActivity.this, "edfwerfger", Toast.LENGTH_LONG).show();
                return true;
            }
        });

        browser.loadUrl("http://www.google.com");
    }

    private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
}

Upvotes: 1

Views: 1966

Answers (1)

Chirag Kalathiya
Chirag Kalathiya

Reputation: 414

Use NavigationDelegate for disable click

 navigationDelegate: (NavigationRequest request) {
       return NavigationDecision.prevent;
 },

Upvotes: 0

Related Questions