需要网络视图的帮助

发布于 2024-11-03 08:54:40 字数 1808 浏览 1 评论 0原文

    final Context myApp = this;  

    /* An instance of this class will be registered as a JavaScript interface */  
    class MyJavaScriptInterface  
    {  
        @SuppressWarnings("unused")  
        public void showHTML(String html)  
        {  
            new AlertDialog.Builder(myApp)  
                .setTitle("HTML")  
                .setMessage(html)  
                .setPositiveButton(android.R.string.ok, null)  
            .setCancelable(false)  
            .create()  
            .show();  


        }  
    }  

    final WebView browser = (WebView)findViewById(R.id.browser);  
    /* JavaScript must be enabled if you want it to work, obviously */  
    browser.getSettings().setJavaScriptEnabled(true);  

    /* Register a new JavaScript interface called HTMLOUT */  
    browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");  

    /* WebViewClient must be set BEFORE calling loadUrl! */  
    browser.setWebViewClient(new WebViewClient() {  
        @Override  
        public void onPageFinished(WebView view, String url)  
        {  
            /* This call inject JavaScript into the page which just finished loading. */  
            browser.loadUrl("javascript:window.HTMLOUT.showHTML(''+document.getElementsByTagName('html')[0].innerHTML+'');");  
        }  
    });  

    /* load a web page */  
    browser.loadUrl("http://lexandera.com/files/jsexamples/gethtml.html");  

在上面的代码中,


             new AlertDialog.Builder(myApp)  
                .setTitle("HTML")  
                .setMessage(html)  
                .setPositiveButton(android.R.string.ok, null)  
            .setCancelable(false)  
            .create()  
            .show(); 


我想将按钮的可见性设置为真和假,但它给了我错误,有人知道为什么会发生这种情况并有任何解决方案吗? 提前致谢

    final Context myApp = this;  

    /* An instance of this class will be registered as a JavaScript interface */  
    class MyJavaScriptInterface  
    {  
        @SuppressWarnings("unused")  
        public void showHTML(String html)  
        {  
            new AlertDialog.Builder(myApp)  
                .setTitle("HTML")  
                .setMessage(html)  
                .setPositiveButton(android.R.string.ok, null)  
            .setCancelable(false)  
            .create()  
            .show();  


        }  
    }  

    final WebView browser = (WebView)findViewById(R.id.browser);  
    /* JavaScript must be enabled if you want it to work, obviously */  
    browser.getSettings().setJavaScriptEnabled(true);  

    /* Register a new JavaScript interface called HTMLOUT */  
    browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");  

    /* WebViewClient must be set BEFORE calling loadUrl! */  
    browser.setWebViewClient(new WebViewClient() {  
        @Override  
        public void onPageFinished(WebView view, String url)  
        {  
            /* This call inject JavaScript into the page which just finished loading. */  
            browser.loadUrl("javascript:window.HTMLOUT.showHTML(''+document.getElementsByTagName('html')[0].innerHTML+'');");  
        }  
    });  

    /* load a web page */  
    browser.loadUrl("http://lexandera.com/files/jsexamples/gethtml.html");  

In to the above code after



             new AlertDialog.Builder(myApp)  
                .setTitle("HTML")  
                .setMessage(html)  
                .setPositiveButton(android.R.string.ok, null)  
            .setCancelable(false)  
            .create()  
            .show(); 


I want to set visibility of the button true and false but it gives me error does any one have any idea why its happens and have any solution?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-11-10 08:54:40

最后我得到了错误的解决方案。我正在使用:

btn.post(new Runnable() {
    @Override
    public void run() {
        btn.requestFocus();
        btn.setVisibility(0);
    }
}

之后,当我想显示按钮时,我开始一个新线程

Finally I got the solution of the error. I'm using:

btn.post(new Runnable() {
    @Override
    public void run() {
        btn.requestFocus();
        btn.setVisibility(0);
    }
}

And after that I'm starting a new thread when I want to show the button

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文