Android WebView的使用
2010-07-19 23:13:00 来源:WEB开发网btn = (Button) this.findViewById(R.id.Button01);
wv = (WebView) this.findViewById(R.id.WebView);
ws = wv.getSettings();
ws.setAllowFileAccess(true);//设置允许访问文件数据
ws.setJavaScriptEnabled(true);//设置支持javascript脚本
ws.setBuiltInZoomControls(true);//设置支持缩放
wv.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view,String url){
//当有新连接时,使用当前的 WebView
view.loadUrl(url);
return true;
}
});
wv.setWebChromeClient(new WebChromeClient(){
public boolean onJsAlert(WebView view,String url,String message,final JsResult result){
//构建一个Builder来显示网页中的alert对话框
Builder builder = new Builder(Test.this);
builder.setTitle("提示对话框");
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
result.confirm();
}
});
builder.setCancelable(false);
builder.create();
builder.show();
return true;
}
public boolean onJsConfirm(WebView view,String url,String message,final JsResult result){
Builder builder = new Builder(Test.this);
builder.setTitle("带选择的对话框");
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
result.confirm();
}
});
builder.setNeutralButton(android.R.string.cancel, new AlertDialog.OnClickListener(){
更多精彩
赞助商链接