WEB开发网
开发学院手机开发Android 开发 Android WebView的使用 阅读

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.

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(){

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Android WebView 使用

编辑录入:coldstar [复制链接] [打 印]
赞助商链接