问题
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