需要webview的帮助

问题描述 投票:0回答:1
    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(); 


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

javascript android html button webview
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.