Fragment里使用CordovaWebView
来源:互联网 发布:mac下方图标隐藏 编辑:程序博客网 时间:2024/06/10 02:38
因为CordovaWebView 默认的初始化里判断了Content是不是继承CordovaInterface,如果直接使用Fragment继承CordovaInterface,CordovaInterface有个抽象方法getActicity ()和Fragment的相冲突了,并且Fragment的这个同名方法还是final的,无法覆盖。
查看CordovaWebView的源码,它是这样实现的。
public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); if (CordovaInterface.class.isInstance(context)) { this.cordova = (CordovaInterface) context; } else { Log.d(TAG, "Your activity must implement CordovaInterface to work"); } this.setWebChromeClient(new CordovaChromeClient(this.cordova)); this.initWebViewClient(this.cordova); this.loadConfiguration(); this.setup(); }
所以只要让CordovaWebView的Content是实现CordovaInterface的接口就可以了。
实现一个类继承接口CordovaInterface:
private class CordovaContext extends ContextWrapper implements CordovaInterface { Activity activity; protected final ExecutorService threadPool = Executors.newCachedThreadPool(); public CordovaContext(Activity activity) { super(activity.getBaseContext()); this.activity = activity; } public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) { //activity.startActivityForResult(command, intent, requestCode); } public void setActivityResultCallback(CordovaPlugin plugin) { //activity.setActivityResultCallback(plugin); } public Activity getActivity() { return activity; } public Object onMessage(String id, Object data) { return null; } public ExecutorService getThreadPool() { return threadPool; } }
inflater = cloneInContext(new CordovaContext(mActivity);
这样就可以实现Fragment里正常使用CordovaWebView。
0 0
- Fragment里使用CordovaWebView
- Fragment里使用 PhoneGap 的 CordovaWebView
- 如何在Fragment中使用phonegap的CordovaWebView
- 如何在Fragment中使用phonegap的CordovaWebView
- PhoneGap使用CordovaWebView时注意事项
- 如何使用fragment里的控件
- 使用标准库里的fragment
- Fragment 里套Fragment
- Android里什么时候使用fragment什么时候使用activity呢?
- ViewPager与support包里的Fragment家族一起使用
- 关于fragment里使用onActivityResult,与onresume等问题
- 使用MenuDrawer在Fragment里完成侧滑菜单
- phonegap使用的初步研究(一)cordovaWebView不能加载外网的页面
- 解决Fragment中使用ViewPager时,ViewPager里的Fragment错位和空白问题
- 解决Fragment中使用ViewPager时,ViewPager里的Fragment错位和空白问题。
- 在xml文件里使用<fragment>报android.view.InflateException: Error inflating class fragment
- 解决Fragment中使用ViewPager时,ViewPager里的Fragment错位和空白问题。
- (4.3.1.12)Fragment中使用ViewPager时,ViewPager里的Fragment错位和空白问题。
- Oracle ORA-01033: ORACLE initialization or shutdown in progress 错误解决办法
- Spring2+struts2+ibatis整合
- 解决ECShop首页缩略图和产品页图片模糊方法
- JFreeChart的使用
- Servlet入门总结及第一个Servlet程序
- Fragment里使用CordovaWebView
- Linux C++学习之路
- 加载jar
- 光子支付
- 单例创建及宏实现单例
- 用dbcp连接池链接RAC集群,怎么配置啊?
- C++第三章
- 自用矩阵操作
- ZOJ 2412 Farm Irrigation 建图BFS