1.了解混合開發(fā):http://www.infoq.com/cn/articles/hybrid-app-development-combat/
2.極致Hybrid 混合式開發(fā)案例, H5優(yōu)化:https://yq.aliyun.com/articles/43
實例:
1抛蚁、在Android Studio中添加assets目錄,首先調(diào)整成project模式,在main的目錄下新建一文件夾叫:assets 显沈。 WebView\src\main\assets
在項目的WebView.iml中加入: <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
2者蠕、創(chuàng)建一個Activity并级,創(chuàng)建webView加載html文件
package com.example.zifae.myapplication;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class WebViewActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//創(chuàng)建webview
WebView webView = new WebView(this);
//切換到內(nèi)容view
setContentView(webView);
//獲取webView配置
WebSettings ws = webView.getSettings();
//啟用JS
ws.setJavaScriptEnabled(true);
//loading assets
myWebView.setWebViewClient(new WebViewClient() {
//點擊網(wǎng)頁中按鈕時酵幕,讓其還在原頁面打開
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
}