我在我的 android 项目中使用CordovaWebView 。当我运行应用程序应用程序加载捕获并显示空白 toast 消息时。在 logcat 中我看到一个错误,说资产中不存在文件。我将jar文件添加到库中,并在我的活动布局中添加了CordovaWebView
<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(而不是CordovaWebView)加载它。
请与我分享您解决此问题的想法。
问候。