如何获得在Android的从web视图文本?视图、如何获得、文本、web

2023-09-07 22:44:50 作者:玩笑中常常藏着真心话

我怎样才能在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,< D​​IV CONTENTEDITABLE = \真正的\风格= \高度:220px; \>< / DIV>中,text / html的,UTF-8,关于:空白);
 

解决方案

您应该获取HTML标记的值从这个类

 类MyJavaScriptInterface
{

        私人上下文CTX;

        MyJavaScriptInterface(上下文CTX)
        {
            this.ctx = CTX;
        }

        公共无效showHTML(字符串HTML)
        {
             字符串HTML标签=的HTML;
        }
}
 
Android手机端有哪些是目录树视图的文件管理器 就是图上那样,图上的是X plore,目前我唯

在上面的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.

 
精彩推荐
图片推荐