我有一个带有 3 个选项卡的 TabbedActivity。每周、转接和通话。Transfer Activity 包含一个我想在每次设备重新定向时维护的 WebView。我发现了大量的例子,这些例子让我看到了下面的内容。这样,WebView 似乎恢复到已保存的实例,并且在 OnProgressChange 期间显示的 ProgressDialog 在重新定向后不会显示备份。但是,WebView 显示的站点中有复选框。如果它们在横向中被选中,然后变成纵向(反之亦然),复选框都会返回到它们原来的未选中状态。我的 DropDownLists 也是如此。
[Activity]
public class Transfer : Activity
{
private WebView web;
private static ProgressDialog progress;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Transfer);
web = (WebView)FindViewById(Resource.Id.web);
progress = new ProgressDialog(this);
if (bundle == null)
{
web.Settings.JavaScriptEnabled = true;
web.SetWebChromeClient(new CustomWebChromeClient(this));
web.SetWebViewClient(new CustomWebViewClient(this));
web.ClearCache(true);
web.LoadUrl("http://www.mysite.com");
}
else
{
web.RestoreState(bundle);
}
}
protected override void OnSaveInstanceState(Bundle outState)
{
web.SaveState(outState);
}
private class CustomWebChromeClient : WebChromeClient
{
private readonly Activity _context;
public CustomWebChromeClient(Activity context)
{
_context = context;
}
public override void OnProgressChanged(WebView view, int newProgress)
{
progress.SetTitle(newProgress + "%");
if (!progress.IsShowing)
{
progress.SetMessage("Please Wait...");
progress.Show();
}
}
}
private class CustomWebViewClient : WebViewClient
{
private readonly Activity _context;
public CustomWebViewClient(Activity context)
{
_context = context;
}
public override void OnPageFinished(WebView view, string url)
{
if (progress.IsShowing)
progress.Hide();
}
}
}