Android webView 禁用维基百科搜索栏 [英] Android webView disable Wikipedia search bar

查看:24
本文介绍了Android webView 禁用维基百科搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用 webView 并加载维基百科网页的应用程序.我想禁用这部分:

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.

谢谢.

推荐答案

通过查看维基百科的源代码,您可以看到搜索栏位于一个 div 容器内,类名为header-容器标题-镀铬".您可以使用JavaScripct 代码和HTML DOM getElementsByClassName() 方法 从视图中删除它.

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.

以下代码可能会帮助您从 HTML 页面中删除搜索栏并显示其余部分.

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);

这篇关于Android webView 禁用维基百科搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆