简易安卓APP 基于HTML5 开发
适合批量生产简单的Web APP应用
1. mainfest 添加互联网访问权限
1 |
<uses-permission android:name="android.permission.INTERNET" /> |
2. 调用网页的代码 Loadurl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.mycompany; import android.app.Activity; import android.os.Bundle; import android.webkit.WebChromeClient; import android.webkit.WebView; public class HelloWebApp extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView webView = (WebView)findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new WebChromeClient()); webView.loadUrl("http://www.baidu.com"); } } |
3. 设置其他的
像返回 刷新的按钮 等等
1 2 3 4 5 6 7 |
public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack() { myWebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } |