
正文
Android PhoneGap 利用 Activity 实现 CordovaInterface
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1.修改main.xml
<?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" >
<org.apache.cordova.CordovaWebView
android:id="@+id/cordovaWebView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2.修改Activity,实现CordovaInterface接口成员。
public class DemoActivity extends Activity implements CordovaInterface { private final ExecutorService threadPool = Executors.newCachedThreadPool();
private CordovaWebView cordovaWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main); cordovaWebView = (CordovaWebView) findViewById(R.id.cordovaWebView1); cordovaWebView.loadUrl("file:///android_asset/www/index.html");
} @Override
public void onDestroy() {
super.onDestroy();
if (cordovaWebView != null) {
cordovaWebView.handleDestroy();
}
} @Override
public void startActivityForResult(CordovaPlugin command, Intent intent,
int requestCode) {
// TODO Auto-generated method stub
}
@Override
public void setActivityResultCallback(CordovaPlugin plugin) {
// TODO Auto-generated method stub
}
@Override
public Activity getActivity() {
// TODO Auto-generated method stub
return this;
}
@Override
public Object onMessage(String id, Object data) {
// TODO Auto-generated method stub
return null;
}
@Override
public ExecutorService getThreadPool() {
// TODO Auto-generated method stub
return threadPool;
}
}
注:程序退出提示注销webView
3.可以在清单文件中的application节点,修改android:theme:AppTheme,不显示应用程序标题栏
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>







