72 Android WebView AlertDialog
2014-01-17 16:30
323 查看
package com.example.android_webview_loaddata; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.view.Menu; import android.view.Window; import android.webkit.JsResult; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class MainActivity extends Activity { private WebView webview; @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webview = (WebView) this.findViewById(R.id.webView1); // String summary = // "<html><body>You scored <b>192</b> points.</body></html>"; // webview.loadData(summary, "text/html", null); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true);// 表示webview可执行服务器端的JS代码 webview.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { // TODO Auto-generated method stub AlertDialog.Builder builder =new AlertDialog.Builder(MainActivity.this); builder.setTitle("提示"); builder.setMessage(message); builder.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub result.confirm();//表示确认用户的选择 } }); builder.create().show(); return super.onJsAlert(view, url, message, result); } }); webview.loadUrl("http://baidu.com"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
相关文章推荐
- android webview onJsAlert 注意事项
- android webview js alert对话框 不能弹出 解决办法
- android webview onJsAlert只调用一次的问题
- 在Android的webview中定做js的alert,confirm和prompt对话框的方法
- android webview js alert对话框 不能弹出 解决办法
- (转)在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- AlertDialog.Builder发生:android.view.WindowManager$BadTokenException: Unable to add window
- android端webview js alert对话框--不能弹出--解决办法
- Android开发实现AlertDialog中View的控件设置监听功能分析
- Android webView中alert无法显示
- Android 改变AlertDialog中View字体的大小
- Android AlertDialog 方法setView(view,0,0,0,0)开发自定义对话框
- Android webview调用js代码无效 webView.loadUrl("javascript:alert('hello')")
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- android webview onJsAlert只调用一次的问题
- android webview获取js中的alert、confirm、和prompt,以及获取其值
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- Android webview中定制js的alert,confirm和prompt对话框的方法 (处理webview 带网站地址的弹出框)