Cordova有自己封装的SystemWebview类,如果要用混合开发andoird Activity继承cordovaActivity后:
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="top"
>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaa"/>
<org.apache.cordova.engine.SystemWebView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/cordova_webview"/>
</LinearLayout>
java:
import android.os.Bundle;
import org.apache.cordova.*;
import org.apache.cordova.engine.SystemWebView;
import org.apache.cordova.engine.SystemWebViewEngine;
public class MainActivity extends CordovaActivity
{
public SystemWebView systemWebView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
// loadUrl(launchUrl);
setContentView(R.layout.mainpage);
LOG.setLogLevel(LOG.DEBUG);//设置日志级别
systemWebView = (SystemWebView)findViewById(R.id.cordova_webview);
ConfigXmlParser parser = new ConfigXmlParser();
parser.parse(this);//这里会解析res/xml/config.xml配置文件
CordovaWebView cordovaWebView = new CordovaWebViewImpl(new SystemWebViewEngine(systemWebView));//创建一个cordovawebview
cordovaWebView.init(new CordovaInterfaceImpl(this), parser.getPluginEntries(), parser.getPreferences());//初始化
systemWebView.loadUrl("file:///android_asset/www/index.html");
}
}
即可;