如何在Fragment中使用phonegap的CordovaWebView
来源:互联网 发布:知乎提问该问题已存在 编辑:程序博客网 时间:2024/05/17 00:07
就为这个问题翻遍国内外各大论坛 功夫不负有心人 终于在github上找到答案
原文地址:https://github.com/Adobe-Marketing-Cloud/app-sample-android-phonegap/wiki/Embed-Webview-in-Android-Fragment
废话不多说直接上代码
希望能帮助到需要的朋友
public class FragmentHtml extends Fragment implements CordovaInterface {private CordovaWebView webView = null;public void setSlidingMenu(SlidingMenu slidingMenu) {this.slidingMenu = slidingMenu;}public static FragmentHtml newInstance() {FragmentHtml fragment = new FragmentHtml();return fragment;}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {context = inflater.getContext();LayoutInflater localInflater = inflater.cloneInContext(new CordovaContext(getActivity(), this));View rootView = localInflater.inflate(R.layout.fragment_html, container, false);webView = (CordovaWebView) rootView.findViewById(R.id.web_report);Config.init(getActivity());//webView.loadUrl(Config.getStartUrl()); webView.loadUrl("file:///android_asset/www/index.htm"); return rootView;}// Plugin to call when activity result is receivedprotected CordovaPlugin activityResultCallback = null;protected boolean activityResultKeepRunning;// Keep app running when pause is received. (default = true)// If true, then the JavaScript and native code continue to run in the// background// when another application (activity) is started.protected boolean keepRunning = true;private final ExecutorService threadPool = Executors.newCachedThreadPool();public Object onMessage(String id, Object data) {return null;}public void onDestroy() {super.onDestroy();if (webView.pluginManager != null) {webView.pluginManager.onDestroy();}}@Overridepublic ExecutorService getThreadPool() {return threadPool;}@Overridepublic void setActivityResultCallback(CordovaPlugin plugin) {this.activityResultCallback = plugin;}public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {this.activityResultCallback = command;this.activityResultKeepRunning = this.keepRunning;// If multitasking turned on, then disable it for activities that return// resultsif (command != null) {this.keepRunning = false;}// Start activitysuper.startActivityForResult(intent, requestCode);}@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent intent) {super.onActivityResult(requestCode, resultCode, intent);CordovaPlugin callback = this.activityResultCallback;if (callback != null) {callback.onActivityResult(requestCode, resultCode, intent);}}private class CordovaContext extends ContextWrapper implements CordovaInterface {CordovaInterface cordova;public CordovaContext(Context base, CordovaInterface cordova) {super(base);this.cordova = cordova;}public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {cordova.startActivityForResult(command, intent, requestCode);}public void setActivityResultCallback(CordovaPlugin plugin) {cordova.setActivityResultCallback(plugin);}public Activity getActivity() {return cordova.getActivity();}public Object onMessage(String id, Object data) {return cordova.onMessage(id, data);}public ExecutorService getThreadPool() {return cordova.getThreadPool();}}}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="0dp"> <org.apache.cordova.CordovaWebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id = "@+id/rl_title"/></LinearLayout>
0 0
- 如何在Fragment中使用phonegap的CordovaWebView
- 如何在Fragment中使用phonegap的CordovaWebView
- Fragment里使用 PhoneGap 的 CordovaWebView
- 在PhoneGap应用中拦截CordovaWebView的url
- Fragment里使用CordovaWebView
- PhoneGap使用CordovaWebView时注意事项
- phonegap使用的初步研究(一)cordovaWebView不能加载外网的页面
- phonegap学习之CordovaWebView
- phonegap学习之CordovaWebView
- 如何在phonegap中使用自带浏览器打开链接
- 如何在phonegap中使用自带浏览器打开链接
- 如何在Fragment中使用findViewById呢?
- 在Fragment中如何使用Toolbar
- MPAndroidChart如何在Fragment中使用
- 如何在Fragment中使用findViewById
- 如何在phonegap中监听数据加载的事件
- phonegap在android中如何退出程序
- Android: 如何在Fragment中使用上下文Context
- MVC4 伪静态设置
- WebServie——CXF客户端生成
- C/C++编程之内存管理
- POJ 2778 DNA Sequence AC自动机DP的矩阵优化
- 常量指针与指针常量
- 如何在Fragment中使用phonegap的CordovaWebView
- Shell 数组/Arrays
- struts2中的result的总结
- 笔记本样式表单
- Android 系统启动不起原因查找
- 总帐接口表详细说明
- fwrite 换行
- 购物车js代码
- python字符串str和字节数组相互转化