TWi*_*lly 11 android webview android-fragments cordova
我刚刚升级到cordova 4.0 for android.我使用以下帖子在片段中加载cordova webview ..
从3.*升级到cordova 4.0后,此代码不再有效.*
具体来说,这第二行就是例外......
LayoutInflater localInflater = inflater.cloneInContext(new CordovaContext(getActivity(), this));
View v = localInflater.inflate(R.layout.dialog_webview, container, false);
Run Code Online (Sandbox Code Playgroud)
这个标签在我的布局文件中...
<org.apache.cordova.CordovaWebView
android:layout_below="@+id/DialogTopBar"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id = "@+id/myWebView"
/>
Run Code Online (Sandbox Code Playgroud)
异常消息......
android.view.InflateException:二进制XML文件行#43:类不是View org.apache.cordova.CordovaWebView
有没有人对如何解决这个问题有任何想法?
看起来好像自Cordova 4.0以来,CordovaWebView类已经改变了......
public class CordovaWebView extends WebView
Run Code Online (Sandbox Code Playgroud)
至
public interface CordovaWebView
Run Code Online (Sandbox Code Playgroud)
不确定这是否正确,但我通过将新的4.0 CordovaActivity.java文件中的一些代码复制到我的片段来手动设置CordovaWebView.
步骤1.在布局中删除CordovaWebView xml标记.
步骤2.将以下代码添加到片段以手动创建CordovaWebView并将其注入片段.
private CordovaWebView webView;
// Read from config.xml:
protected CordovaPreferences preferences;
protected String launchUrl;
protected ArrayList<PluginEntry> pluginEntries;
protected CordovaInterfaceImpl cordovaInterface;
protected void loadConfig() {
ConfigXmlParser parser = new ConfigXmlParser();
parser.parse(getActivity());
preferences = parser.getPreferences();
preferences.setPreferencesBundle(getActivity().getIntent().getExtras());
preferences.copyIntoIntentExtras(getActivity());
launchUrl = parser.getLaunchUrl();
pluginEntries = parser.getPluginEntries();
// Config.parser = parser;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
LayoutInflater localInflater = inflater.cloneInContext(new CordovaContext(getActivity(), this));
View v = localInflater.inflate(R.layout.dialog_webview, container, false);
cordovaInterface = new CordovaInterfaceImpl(getActivity());
if(savedInstanceState != null)
cordovaInterface.restoreInstanceState(savedInstanceState);
loadConfig();
webView = new CordovaWebViewImpl(CordovaWebViewImpl.createEngine(getActivity(), preferences));
webView.getView().setId(100);
RelativeLayout.LayoutParams wvlp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
wvlp.addRule(RelativeLayout.BELOW,R.id.DialogTopBar);
webView.getView().setLayoutParams(wvlp);
if (!webView.isInitialized()) {
webView.init(cordovaInterface, pluginEntries, preferences);
}
cordovaInterface.onCordovaInit(webView.getPluginManager());
// webView = (SystemWebView)v.findViewById(R.id.myWebView);
// Config.init(getActivity());
((RelativeLayout)v).addView(webView.getView());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4513 次 |
| 最近记录: |