简体   繁体   中英

Android. Webview. How to make element unclickable?

WebView is loading data from url .

wvBrowser.loadUrl(MainActivity.URL_ABOUT);

On WebViewClient's onPageStarted method I am trying to use javascript:

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        String javascript = "javascript: "
                + "document.getElementById('logo').setAttribute(\"style\",\"pointer-events: none ;\");";
        view.loadUrl(javascript);
    }

Result: element is still clickable.

How to make only one element unclickable?

webView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
       return true; //True if the listener has consumed the event, false otherwise. 
    }  
});

It will disable the webview touch event

webView.setFocusableInTouchMode(false);
webView.setFocusable(false);

It will make the links non-focusable.

Check this for more customization using javascript in android

https://stackoverflow.com/a/4075955/3020568

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM