现在的位置: 首页 > 综合 > 正文

android + WebView 关闭提示程序

2014年08月29日 ⁄ 综合 ⁄ 共 1366字 ⁄ 字号 评论关闭
package com.example.domeapp;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.*;
import android.view.KeyEvent;
import android.app.*;
import android.content.DialogInterface;

public class MainActivity extends Activity {
	private WebView mWebView;
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.activity_main);
		mWebView = (WebView) findViewById(R.id.webView1);
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.loadUrl("file:///android_asset/ceshi.html");
		mWebView.setWebViewClient(new HelloWebViewClient());
	}
	

	private void showTips() {
		AlertDialog alertDialog = new AlertDialog.Builder(this)
				.setTitle("退出程序").setMessage("是否退出程序")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						finish();
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						return;

					}
				}).create();
		alertDialog.show();
	}

	public boolean onKeyDown(int KeyCode, KeyEvent event) {
		if (KeyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			showTips();
			return false;
		}
		return super.onKeyDown(KeyCode, event);
	}

	private class HelloWebViewClient extends WebViewClient {
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}

}

网站收集一款android 代码 可以用html5 来做一个网页app

抱歉!评论已关闭.