Webview with Buttons, Unhide-Hide

EDDreamEDDream USMember

I have a Webview with a button hide, so, I need when the "Webview" reaches a certain url the button unhide, anyone has any idea how to do that?

Thanks in advance.

Best Answer

  • YkshLeoYkshLeo US ✭✭✭✭
    edited May 2016 Accepted Answer

    @EDDream, Try something like this :

    public class MainActivity : Activity
    {
        private static WebView webView;
        private static Button button;
        WebViewClient webViewClient = new MyWebViewClient ();
    
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Main);
    
            button = FindViewById<Button> (Resource.Id.myButton);
            webView = FindViewById<WebView> (Resource.Id.myWebView);
    
            webView.SetWebViewClient (webViewClient);
    
            webView.Post (() => {
                webView.ClearCache (true);  
                webView.Settings.JavaScriptEnabled = true;
                webView.Settings.JavaScriptCanOpenWindowsAutomatically = false;
                webView.LoadUrl ("Your_Url");
            });
    
        }
    
        private class MyWebViewClient : WebViewClient
        {
            public override void OnPageFinished (WebView view, string url)
            {
                base.OnPageFinished (view, url);
                button.Visibility = ViewStates.Gone;
            }
        }
    }
    

    Refer : https://github.com/xamarin/monodroid-samples/blob/master/MonoIO/UI/MapFragment.cs

Answers

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited May 2016 Accepted Answer

    @EDDream, Try something like this :

    public class MainActivity : Activity
    {
        private static WebView webView;
        private static Button button;
        WebViewClient webViewClient = new MyWebViewClient ();
    
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Main);
    
            button = FindViewById<Button> (Resource.Id.myButton);
            webView = FindViewById<WebView> (Resource.Id.myWebView);
    
            webView.SetWebViewClient (webViewClient);
    
            webView.Post (() => {
                webView.ClearCache (true);  
                webView.Settings.JavaScriptEnabled = true;
                webView.Settings.JavaScriptCanOpenWindowsAutomatically = false;
                webView.LoadUrl ("Your_Url");
            });
    
        }
    
        private class MyWebViewClient : WebViewClient
        {
            public override void OnPageFinished (WebView view, string url)
            {
                base.OnPageFinished (view, url);
                button.Visibility = ViewStates.Gone;
            }
        }
    }
    

    Refer : https://github.com/xamarin/monodroid-samples/blob/master/MonoIO/UI/MapFragment.cs

  • EDDreamEDDream USMember

    @YkshLeo said:
    @EDDream, Try something like this :

    public class MainActivity : Activity
    {
      private static WebView webView;
      private static Button button;
      WebViewClient webViewClient = new MyWebViewClient ();
    
      protected override void OnCreate (Bundle bundle)
      {
          base.OnCreate (bundle);
          SetContentView (Resource.Layout.Main);
    
          button = FindViewById<Button> (Resource.Id.myButton);
          webView = FindViewById<WebView> (Resource.Id.myWebView);
    
          webView.SetWebViewClient (webViewClient);
          
          webView.Post (() => {
              webView.ClearCache (true);  
              webView.Settings.JavaScriptEnabled = true;
              webView.Settings.JavaScriptCanOpenWindowsAutomatically = false;
              webView.LoadUrl ("Your_Url");
          });
    
      }
    
      private class MyWebViewClient : WebViewClient
      {
          public override void OnPageFinished (WebView view, string url)
          {
              base.OnPageFinished (view, url);
              button.Visibility = ViewStates.Gone;
          }
      }
    }
    

    Refer : [https://github.com/xamarin/monodroid-samples/blob/master/MonoIO/UI/MapFragment.cs][1]

    [1]: https://github.com/xamarin/monodroid-samples/blob/master/MonoIO/UI/MapFragment.cs#L123

    Thank you!!! :smile:

Sign In or Register to comment.