1、uniapp項(xiàng)目打包
vue版本選擇2.0
?記住一點(diǎn),打包H5前修改配置,否則在Android中打開會(huì)白屏,修改方式如下
打包成H5,打包后可以在瀏覽器打開確保有內(nèi)容
2、將打包后的uniappH5拷貝到Android項(xiàng)目
assets文件夾沒有就自己建
3、Android部分代碼
xml布局文件處加入一個(gè)webview標(biāo)簽
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
Activity的 onCreate周期加入如下代碼
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new JsInterface(this), "AndroidContext");
mWebView.loadUrl("file:///android_asset/uniapp/index.html");
JsInterface
public class JsInterface {
private Context mContext;
public JsInterface(Context context) {
mContext = context;
}
@JavascriptInterface
public Context getContext() {
return mContext;
}
}
運(yùn)行項(xiàng)目就可以看到uniAPP的頁面了文章來源:http://www.zghlxwxcb.cn/news/detail-834086.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-834086.html
到了這里,關(guān)于原生Android與uniapp開發(fā)的H5混合開發(fā)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!