1.了解混合开发:http://www.infoq.com/cn/articles/hybrid-app-development-combat/
2.极致Hybrid 混合式开发案例, H5优化:https://yq.aliyun.com/articles/43
实例:
1、在Android Studio中添加assets目录,首先调整成project模式,在main的目录下新建一文件夹叫:assets 。 WebView\src\main\assets
在项目的WebView.iml中加入: <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
2、创建一个Activity,创建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);
//创建webview
WebView webView = new WebView(this);
//切换到内容view
setContentView(webView);
//获取webView配置
WebSettings ws = webView.getSettings();
//启用JS
ws.setJavaScriptEnabled(true);
//loading assets
myWebView.setWebViewClient(new WebViewClient() {
//点击网页中按钮时,让其还在原页面打开
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
}
网友评论