Java文件配置:官方说明不够清晰
1 package org.apache.cordova.example; 2 3 import java.util.concurrent.ExecutorService; 4 import java.util.concurrent.Executors; 5 6 import android.app.Activity; 7 import android.content.Context; 8 import android.content.Intent; 9 import android.os.Bundle; 10 import org.apache.cordova.*; 11 import org.apache.cordova.api.CordovaInterface; 12 import org.apache.cordova.api.CordovaPlugin; 13 14 public class cordovaExample extends Activity implements CordovaInterface{ 15 16 CordovaWebView cordovaWebView; 17 18 private final ExecutorService threadPool =Executors.newCachedThreadPool(); 19 20 @Override 21 public void onCreate(Bundle savedInstanceState) { 22 super.onCreate(savedInstanceState); 23 24 setContentView(R.layout.main); 25 26 cordovaWebView=(CordovaWebView) findViewById(R.id.tutoriaView); 27 28 cordovaWebView.loadUrl("file:///android_asset/www/index.html"); 29 } 30 31 @Override 32 public void cancelLoadUrl() { 33 34 } 35 36 @Override 37 public Activity getActivity() { 38 return this; 39 } 40 41 @Override 42 public Context getContext() { 43 return this.getContext(); 44 } 45 46 @Override 47 public ExecutorService getThreadPool() { 48 return threadPool; 49 } 50 51 @Override 52 public Object onMessage(String string, Object object) { 53 return null; 54 } 55 56 @Override 57 public void setActivityResultCallback(CordovaPlugin cordovaPlugin) { 58 59 } 60 61 @Override 62 public void startActivityForResult(CordovaPlugin plugin, Intent intent, int i) { 63 64 } }
R.layout.main文件配置,不明白官方文档为什么写成res/xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="fill_parent" 5 android:layout_height="fill_parent" 6 > 7 8 <org.apache.cordova.CordovaWebView 9 android:id="@+id/tutoriaView" 10 android:layout_width="match_parent" 11 android:layout_height="match_parent"/> 12 </LinearLayout>
从容是一种态度。