我正在尝试将硬件后退按钮链接到Android Xamarin中的WebView中。我的WebView包含在TabHost的OnCreate实例中(已弃用,但无论如何我都在使用它)我已经将它放在MainActivity : TabActivity
类中
public override void OnBackPressed()
{
base.OnBackPressed();
}
这是我的一个Tab活动类的示例
[Activity]
public class SpeakersActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//set the content view
SetContentView(Resource.Layout.subs);
//declare webview and tell our code where to find the XAML resource
WebView subWebView = FindViewById<WebView>(Resource.Id.webViewSubs);
//set the webview client
subWebView.SetWebViewClient(new WebViewClient());
//load the subscription url
subWebView.LoadUrl("https://www.bitchute.com/subscriptions/");
//enable javascript in our webview
subWebView.Settings.JavaScriptEnabled = true;
//zoom control on? This should perhaps be disabled for consistency?
//we will leave it on for now
subWebView.Settings.BuiltInZoomControls = true;
subWebView.Settings.SetSupportZoom(true);
//scrollbarsdisabled
// subWebView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
subWebView.ScrollbarFadingEnabled = false;
}
}
我已经看到了很多有关如何使用它的信息
subWebView.GoBack();
在Web视图中返回,但是问题是我的WebView不在硬件后退按钮的范围内。硬件后退按钮位于mainactivity类中,而我的Web视图位于选项卡活动的各个实例中。
更正此问题的最佳方法是什么?谢谢!
答案 0 :(得分:0)
非常感谢@SushiHangover !!!
我这样解决了:
[活动] 公共类SpeakersActivity:活动
{
public override void OnBackPressed()
{
WebView subWebView = FindViewById<WebView>(Resource.Id.webViewSubs);
subWebView.GoBack();
}
}