我在我的安卓项目中使用CordovaWebView。当我运行应用程序时,加载catch并显示一条空白的吐司消息。在logcat中,我看到一个错误,即在资产中不存在文件。我将jar文件添加到库中,并在活动布局中添加了
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="11"
android:orientation="vertical" >
<org.apache.cordova.CordovaWebView
android:id="@+id/tutorialView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>并使用此代码从资产加载html文件:
CordovaWebView cwv;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course);
try{
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
cwv.loadUrlIntoView("file:///android_asset/test.html");
}
catch(Exception e)
{
ToastHelper.Long(e.getMessage());
}
}html文件存在于资产中,我可以使用WebView (而不是WebView)加载它。
请与我分享你对解决这个问题的想法。
致以问候。
发布于 2014-08-19 14:32:33
试着使用
cwv.loadUrl("file:///android_asset/test.html");而不是
cwv.loadUrlIntoView("file:///android_asset/test.html");看看这个
发布于 2014-08-19 17:06:11
对于index.html
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap Android App</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<style type="text/css">
@font-face {
font-family: AayatQuraan;
src: url("file:///android_asset/fonts/AayatQuraan.ttf")
}
body {
font-family: AayatQuraan;
font-size: 60px;
text-align: justify;
}
</style>
</head>
<body onload="init();" >
جميل
</body>
</html>对于java
package com.example.hellogap;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html",1000);
}
}输出类似于this=的内容

https://stackoverflow.com/questions/25385448
复制相似问题