是否有可能改变的WebView的上下文中实例化后? [英] Is it possible to change the context of a WebView after it has been instantiated?

查看:1075
本文介绍了是否有可能改变的WebView的上下文中实例化后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的WebView 我加载一个活动,为了拥有它preloaded,使其在不同的活动(从第一个推出)。

I have a WebView I'm loading in an activity in order to have it preloaded so that it pops up immediately in a different Activity (launched from the first).

问题是,为了实例化的WebView ,我有一个上下文传递,在此情况下,它上面提到的第一个。

The problem is that in order to instantiate a WebView, I have to pass in a Context, in this case it's the first mentioned above.

所以它的伟大工程,第二活动显示的WebView 就好了。现在的问题是,如果我点击<选择> 下拉菜单中的的WebView ,其选择对话框显示了下的WebView。这感觉就像选择可言,直到你打后退按钮,并简要看到选择对话框返回到父活动之前不起作用。

So it works great, and the second Activity shows the WebView just fine. The problem is that if I click a <select> dropdown in the WebView, its selector dialog shows up UNDER the WebView. It feels like the select doesn't work at all until you hit the back button and briefly see the selection dialog just before you return to the parent activity.

这好像当我追加的WebView 来的第二个活动的布局,它的情态动词得到重视这项活动的窗口,但 web视图本身被连接到父活动的窗口,因此它示出了在层级较高点

It seems as though when I append the WebView to the layout in the second activity, it's modals get attached to that activity's window, but the WebView itself is attached to the parent activity's window, so it shows in a higher point in the hierarchy.

我怎么可能修改上下文的WebView 它被实例化后?

How can I possibly change the Context of the WebView after it's been instantiated?

这是一个很难解决的问题 - 我有活动开始之前创建的网页视图,但我也需要选择对话框工作

This is a very difficult problem to solve -- I have to create the WebViews before the activity is started, but I also need the selection dialogs to work.

请如果任何人都可以在这里给我一些启发我会非常AP preciate它。

Please if anyone can give me some insights here I'd greatly appreciate it.

这是一个SDK项目,所以我不会有机会获得母公司的活动。此外,saveState和不工作,因为什么在的WebView所示的批量是由JavaScript生成的​​,完整的DOM堆栈不转让。

This is for an SDK project, so I will not have access to the parent activity. Also, saveState isn't working, because the bulk of what is shown in the WebView is generated by JavaScript, and the full DOM stack doesn't transfer.

推荐答案

您可以尝试使用的 MutableContextWrapper

MutableContextWrapper mMutableContext=new MutableContextWrapper(context);
WebView mWebView=new WebView(mMutableContext);

和以后你可以做

mMutableContext.setBaseContext(newcontext);

不过...


  • 的WebView是一个非常复杂的组件,它很可能会使用传递的上下文中创建其他对象一样处理程序。可能的WebView使用这些处理后的东西到原来的UI线程,所以在最后你可能有背景的混合视图,你知道,双内存泄漏(如果它正常工作)

  • WebView is a very complex component that will probably be using the passed context to create other objects like Handlers. WebView probably uses those handlers to post stuff to the original UI thread, so at the end you'll probably have a View with a mix of contexts, you know, a double memory leak (if it ever works properly)

网页视图跨越至少1线的WebCore,也就是那里的行动发生,也在不断的沟通与原来的UI线程与...处理程序?通过独创的背景下?谁知道!

Webview spans at least 1 thread "webcore" that is where the action happens and is also in constant communication with the original UI thread with ... handlers? through the original context? who knows!

有2甚至不同​​的WebView引擎:奇巧是铬为主,同时果冻豆和previous版本使用AOSP /的WebView。所以,你有一个额外的突破点。

There are even 2 different webview engines: Kitkat is chromium-based while jelly bean and previous versions use AOSP/WebView. So you have an additional breaking point.

在说明理由不够强恕我直言。的WebView是不是慢。如果您加载应用程序是,尽量优化。有很多事情可以用于执行操作,如加载HTML&放大器;显卡内部的资产。

The reasons you state are not strong enough imho. WebView is not that slow. If the app you load is, try to optimize it. There are a lot of things you can do for that, like loading the HTML & graphics from internal assets.

这篇关于是否有可能改变的WebView的上下文中实例化后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆