Java文件配置:官方说明不够清晰
package org.apache.cordova.example; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import org.apache.cordova.*; import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.CordovaPlugin; public class cordovaExample extends Activity implements CordovaInterface{ CordovaWebView cordovaWebView; private final ExecutorService threadPool =Executors.newCachedThreadPool(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); cordovaWebView=(CordovaWebView) findViewById(R.id.tutoriaView); cordovaWebView.loadUrl("file:///android_asset/www/index.html"); } @Override public void cancelLoadUrl() { } @Override public Activity getActivity() { return this; } @Override public Context getContext() { return this.getContext(); } @Override public ExecutorService getThreadPool() { return threadPool; } @Override public Object onMessage(String string, Object object) { return null; } @Override public void setActivityResultCallback(CordovaPlugin cordovaPlugin) { } @Override public void startActivityForResult(CordovaPlugin plugin, Intent intent, int i) { } }
R.layout.main文件配置,不明白官方文档为什么写成res/xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <org.apache.cordova.CordovaWebView android:id="@+id/tutoriaView" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout>
从容是一种态度。