Display a part of the webpage on the webview android

前端 未结 3 639
南笙
南笙 2020-11-29 06:08

I want to make an app which loads the content from the webpage into webview. I want to show only a particular thing in the entire webview, not the whole content of the webpa

3条回答
  •  醉酒成梦
    2020-11-29 07:01

    Thank You for the answer Zyber. I have solved it using injection of JavaScript in the code for WebView in android.

    final WebView webview = (WebView)findViewById(R.id.browser);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(new WebViewClient() {
     @Override
    public void onPageFinished(WebView view, String url)
    {
        webview.loadUrl("javascript:(function() { " +
                "document.getElementsByTagName('header')[0].style.display="none"; " +
                "})()");
    }
    });
    webview.loadUrl("http://code.google.com/android");
    

    This solved my purpose and it is easy to use to.

提交回复
热议问题