Android webView disable Wikipedia search bar

拥有回忆 提交于 2020-01-15 07:55:45

问题


I'm building an app which using webView and loading Wikipedia's web pages. I would like to disable this part:

I don't know what is the best way to do this... I have thought of auto scrolling down, but then the user is able to scroll up. Auto scrolling down is also doesn't accurate and may hide some of the value's information.

Thanks.


回答1:


By looking into Wikipedia's source code you can see that the search bar is located inside a div container with the class name "header-container header-chrome". You are able to remove it from the view using JavaScripct code and the HTML DOM getElementsByClassName() Method.

The following code might help you with removing the search bar from the HTML page and display the rest.

WebView myWebViewDisply = (WebView) findViewById(R.id.WebViewDisply);
myWebViewDisply.getSettings().setJavaScriptEnabled(true);
myWebViewDisply.setWebViewClient(new WebViewClient() {

@Override
public void onPageFinished(WebView view, String url) {
    myWebViewDisply.loadUrl("javascript:(function() { " +
        "document.getElementsByClassName
        ('header-container header-chrome')[0].style.display='none';" 
        +"})()");
    }
});
myWebViewDisply.loadUrl(youUrl);


来源:https://stackoverflow.com/questions/42857091/android-webview-disable-wikipedia-search-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!