如何获得在Android的从web视图文本? [英] How to get text from webview in android?
本文介绍了如何获得在Android的从web视图文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能在Android中得到的WebView文本? 下面是我的一些code:
web视图=(web视图)findViewById(R.id.wv_memo);
webView.requestFocus(View.FOCUS_DOWN);
webView.setOnTouchListener(新View.OnTouchListener()
{
@覆盖
公共布尔onTouch(视图V,MotionEvent事件)
{
开关(event.getAction())
{
案例MotionEvent.ACTION_DOWN:
案例MotionEvent.ACTION_UP:
如果(!v.hasFocus())
{
v.requestFocus();
}
打破;
}
返回false;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(真正的);
webSettings.setJavaScriptEnabled(真正的);
webView.addJavascriptInterface(新MyJavaScriptInterface(本),HtmlViewer);
webView.loadDataWithBaseURL(NULL,< DIV CONTENTEDITABLE = \真正的\风格= \高度:220px; \>< / DIV>中,text / html的,UTF-8,关于:空白);
解决方案
您应该获取HTML标记的值从这个类
类MyJavaScriptInterface
{
私人上下文CTX;
MyJavaScriptInterface(上下文CTX)
{
this.ctx = CTX;
}
公共无效showHTML(字符串HTML)
{
字符串HTML标签=的HTML;
}
}
在上面的code,在showHTML()方法中的变量HTML标签有你想要的HTML全文。
How can I get text from webview in android? Here are some of my code:
webView = (WebView)findViewById(R.id.wv_memo);
webView.requestFocus(View.FOCUS_DOWN);
webView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus())
{
v.requestFocus();
}
break;
}
return false;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");
webView.loadDataWithBaseURL(null,"<div contenteditable=\"true\" style=\"height:220px;\"></div>", "text/html", "utf-8", "about:blank");
解决方案
You should have get Html tag's value from this class
class MyJavaScriptInterface
{
private Context ctx;
MyJavaScriptInterface(Context ctx)
{
this.ctx = ctx;
}
public void showHTML(String html)
{
String htmlTags = html;
}
}
In the above code, in showHTML() method the variable htmlTags has full text of html you want.
这篇关于如何获得在Android的从web视图文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文