码迷,mamicode.com
首页 > 移动开发 > 详细

Android PhoneGap 利用 Activity 实现 CordovaInterface

时间:2015-09-02 18:43:36      阅读:449      评论:0      收藏:0      [点我收藏+]

标签:

1.修改main.xml

 1 <?xml version="1.0" encoding="utf-8"?>  
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
 3     android:layout_width="match_parent"  
 4     android:layout_height="match_parent"  
 5     android:orientation="vertical" >  
 6     <org.apache.cordova.CordovaWebView  
 7         android:id="@+id/cordovaWebView1"  
 8         android:layout_width="match_parent"  
 9         android:layout_height="match_parent" />  
10 </LinearLayout>  

2.修改Activity,实现CordovaInterface接口成员。

 1 public class DemoActivity extends Activity implements CordovaInterface {  
 2           
 3         private final ExecutorService threadPool = Executors.newCachedThreadPool();  
 4         private CordovaWebView cordovaWebView;  
 5         @Override  
 6         public void onCreate(Bundle savedInstanceState) {  
 7                 super.onCreate(savedInstanceState);  
 8                  
 9                 setContentView(R.layout.main);  
10                  
11                 cordovaWebView = (CordovaWebView) findViewById(R.id.cordovaWebView1);  
12                  
13                 cordovaWebView.loadUrl("file:///android_asset/www/index.html");  
14         }  
15           
16         @Override  
17         public void onDestroy() {  
18                 super.onDestroy();  
19                 if (cordovaWebView != null) {  
20                         cordovaWebView.handleDestroy();  
21                 }  
22         }  
23           
24         @Override  
25         public void startActivityForResult(CordovaPlugin command, Intent intent,  
26                         int requestCode) {  
27                 // TODO Auto-generated method stub  
28         }  
29         @Override  
30         public void setActivityResultCallback(CordovaPlugin plugin) {  
31                 // TODO Auto-generated method stub  
32         }  
33         @Override  
34         public Activity getActivity() {  
35                 // TODO Auto-generated method stub  
36                 return this;  
37         }  
38         @Override  
39         public Object onMessage(String id, Object data) {  
40                 // TODO Auto-generated method stub  
41                 return null;  
42         }  
43         @Override  
44         public ExecutorService getThreadPool() {  
45                 // TODO Auto-generated method stub  
46                 return threadPool;  
47         }  
48 }  

注:程序退出提示注销webView

3.可以在清单文件中的application节点,修改android:theme:AppTheme,不显示应用程序标题栏

1 <style name="AppTheme" parent="AppBaseTheme">  
2     <item name="android:windowNoTitle">true</item>  
3 </style>  

 

Android PhoneGap 利用 Activity 实现 CordovaInterface

标签:

原文地址:http://www.cnblogs.com/CharlesGrant/p/4779129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!