作者:黑马@梦想 | 来源:互联网 | 2023-07-11 15:21
packagecom.example.domeapp;importandroid.app.Activity;importandroid.os.Bundle;importandroid.webk
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