【问题标题】:Webview does not load every timeWebview 不是每次都加载
【发布时间】:2013-12-22 04:04:03
【问题描述】:

我有一个 Webview,它必须从 assets 文件夹中加载一个静态网页。该网页包含一个完美运行的javascript函数。问题是每隔一段时间 当 Activity 启动时,网页从不出现(而且经常出现。启动 Activity 也包含 webview)

在 webview 加载时,您导航到另一个活动然后返回,此时 webview 不会重新绘制

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    actionBar.AddView(mainActionBar);
    formDialog.AddView(LayoutInflater.Inflate(Resource.Layout.googleGraphInWebview, null));

    formDialog.SetMinimumHeight(400);

    graph = FindViewById<WebView>(Resource.Id.graphView);
    list = FindViewById<ListView>(Resource.Id.AppointmentList); // get reference to the ListView in the layout

    appointments.Add(new AppointmentListItem("Appointment: Appointment with Spur Cresta", "Remember to meet with Mike regarding the cost sales!", Resource.Drawable.Icon));
    appointments.Add(new AppointmentListItem("Appointment: Jone's laundry needs to be collected", "Address: 12 Marry Street Roodepoort", Resource.Drawable.Icon));

    list.Adapter = new AppointmentListViewAdapter(this, appointments);
    list.ItemClick += AppointmentListClick;  // to be defined

    LinearLayout sideWidget = FindViewById<LinearLayout>(Resource.Id.SideWidget);
    sideWidget = FindViewById<LinearLayout>(Resource.Id.SideWidget);
    sideWidget.AddView(LayoutInflater.Inflate(Resource.Layout.LineItem, null));

    graph.Settings.JavaScriptEnabled = true;
    graph.SetWebViewClient(new webView(formDialog));
    graph.LoadUrl("file:///android_asset/graph.html");

}

你能帮忙吗?

一个

【问题讨论】:

  • 或许将LoadUrl 移动到OnResume

标签: android xamarin.android android-webview


【解决方案1】:

所以真正的问题是我不仅需要做上述所有事情,还要专门添加

graph.SetWebChromeClient(new WebChromeClient());
graph.SetWebViewClient(new webView(formDialog));

SetWebChromeClient(new WebChromeClient()); 非常重要。

在我添加此行后,每次加载页面。瞬间

一个

【讨论】:

    猜你喜欢
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    相关资源
    最近更新 更多