首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CordovaWebView错误:无法将org.apache.cordova.CordovaWebView转换为android.view.View

CordovaWebView错误:无法将org.apache.cordova.CordovaWebView转换为android.view.View
EN

Stack Overflow用户
提问于 2015-09-16 18:40:07
回答 2查看 2.2K关注 0票数 5

我对Cordova 5.1.1在Android上的实现有一些问题。我正在尝试在我的应用程序中嵌入一个CordovaWebView。我已经遵循了官方站点中描述的所有指令,但是我不断地得到错误站点不能转换为android.view.View“。我寻找了很多帮助,但我找不到任何可以帮助我的东西。这是我的密码:

活动:

代码语言:javascript
复制
public class CordovaTestActivity extends Activity implements CordovaInterface {

protected CordovaPlugin activityResultCallback = null;
protected boolean activityResultKeepRunning;
protected boolean keepRunning = true;
private final ExecutorService threadPool = Executors.newCachedThreadPool();
CordovaWebView cwv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cordova_test);
    cwv = (CordovaWebView) findViewById(R.id.tutorialView);
    Config.init(this);
    cwv.loadUrl(Config.getStartUrl());
}

@Override
public Activity getActivity() {
    return this;
}

@Override
public ExecutorService getThreadPool() {
    return threadPool;
}

@Override
public Object onMessage(String arg0, Object arg1) {
    return null;
}

@Override
public void setActivityResultCallback(CordovaPlugin plugin) {
    this.activityResultCallback = plugin;
}

@Override
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
     this.activityResultCallback = command;
     this.activityResultKeepRunning = this.keepRunning;

     if (command != null) {
         this.keepRunning = false;
     }

     super.startActivityForResult(intent, requestCode);
}

@Override
protected 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);
     }
} }

xml:

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.cordovatest.CordovaTestActivity" >

<org.apache.cordova.CordovaWebView
 android:id="@+id/tutorialView"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />

</RelativeLayout>

config.xml

代码语言:javascript
复制
<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<preference name="AndroidLaunchMode" value="singleTop" />
<name>Hello World</name>
<description>
    A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="fullscreen" value="false" />
<preference name="webviewbounce" value="true" />
</widget>
EN

回答 2

Stack Overflow用户

发布于 2016-02-24 13:52:00

我知道回答这个问题为时已晚,但今天我面对这个问题,并试图找到解决办法。

在5.1.1Cordova实现中,CordovaWebView从CustomwebView转换为接口,我们不能在布局中使用它,这是应用程序不能编译的原因。

cordova提供的另一个webview实现称为SystemWebView,在org.apache.cordova.engine包下。

我不知道为什么cordova developer将cordovawebview转换为接口

票数 1
EN

Stack Overflow用户

发布于 2018-01-25 15:59:16

我已经找到了解决这个问题的办法。我们可以使用org.apache.cordova.engine.SystemWebView而不是CordovaWebView,它将如预期的那样工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32616257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档