After I use webview - How to get back to the page

edcal2edcal2 Member ✭✭✭

I am using webview to view a web page and do some processing. How do I get back to the page that displayed the web page?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    The webview is just displayed on the page. You can set the webView's visibility to gone to hide the webView in a Button's click event.

    public class MainActivity : AppCompatActivity
    {
        WebView webView;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
    
            webView = FindViewById<WebView>(Resource.Id.webview_);
            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(new HelloWebViewClient());
            webView.LoadUrl("https://www.google.com");
    
            FindViewById<Button>(Resource.Id.button1).Click += delegate
            {
                webView.Visibility = webView.Visibility == ViewStates.Visible ? ViewStates.Gone : ViewStates.Visible;
            };
        }
    }
    

    Or start a new activity to display the WebView. Go back to the previous activity via back button.

Sign In or Register to comment.