需要网络视图的帮助
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我得到了错误的解决方案。我正在使用:
之后,当我想显示按钮时,我开始一个新线程
Finally I got the solution of the error. I'm using:
And after that I'm starting a new thread when I want to show the button