/***
* React Native開發工具、插件(二)
* 說明:我的qq號:1457521527;歡迎互相學習~
* @author yjbo
* @create 2017.03.29 23:00
*/
本文轉發請標明:http://blog.csdn.net/yangjianbo456/article/details/70180248
github地址:https://github.com/hytcyjb/yweb
本文源碼:點擊下載
yweb
爲了將html頁面能夠顯示在android手機上而做的框架
realse 1.0 : 寫一個最簡單的android與html5交互的案例(2017年4月15日01:18:01)
效果:
代碼摘取:
try {
webView.loadUrl("file:///android_asset/testjs.html");
} catch (Exception e) {
e.printStackTrace();
}
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setJavaScriptCanOpenWindowsAutomatically(true);//允許js彈出窗口
settings.setUseWideViewPort(true);
webView.addJavascriptInterface(new InJavaScriptLocalObj(), "local_obj");
//引用http://blog.csdn.net/sensky_yuan/article/details/17356843
//關閉硬件加速;sdk19以下(不包含19)不設置這個就會出現不手動點擊第一個頁面不出現的情況;
if (Build.VERSION.SDK_INT >= 19) {
} else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
//設置 緩存模式
//settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= 19) {//設置是否自動加載圖片
settings.setLoadsImagesAutomatically(true);
} else {
settings.setLoadsImagesAutomatically(false);
}
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
setTitle(title);
}
});
}
/**
* js調用
* @author yjbo @time 2017/4/15 0:19
*/
class InJavaScriptLocalObj {
@JavascriptInterface
public void goback(String kind) {
Message msg = new Message();
msg.what = handleMsg_12;
msg.obj = kind;
mhandler.sendMessage(msg);
}
}
...
github源碼地址:github地址:https://github.com/hytcyjb/yweb
本文源碼:點擊下載
喜歡請幫忙start;
/**
* 有問題可以提問哦!
* @qq 1457521527
* @author yjbo @time 2017/4/15 0:09
*/