[mono-android] WebView goes full screen when in tab layout

Craig Dunn craig.dunn at conceptdevelopment.net
Wed Mar 16 20:14:03 EDT 2011


>>I did have to change BaseActivity to Activity
Oh, sorry, BaseActivity is a custom class in my project - I forgot to
sanitise it out (sorry for any confusion).

Not really sure I know "why" the WebView behaves this way, except to say
that it does give you a lot of flexibility to decide how to handle Url
loading within your app (to intercept actions and control what is loaded).
Incidentally, I *think* if you had chosen a URL that does NOT redirect (you
put LoadUrl("http://www.google.com") in your example) then the WebView would
have probably loaded successfully "in" the tab with your original code - but
then any link you clicked would still have popped-out to a full webbrowser.
The reason the code below helps is because it traps those redirects and
forces them into the same WebView which is normally the behaviour you want.

HTH
cd


On Thu, Mar 17, 2011 at 10:58 AM, <www at gencode.com> wrote:

> Craig,
>
>
>
> That worked, I did have to change BaseActivity to Activity
>
> Was that okay to do?
>
>
>
> Also I don’t really understand why I needed to do this with a webview but
> not a textview as in the tab example
>
>
>
> Ed,
>
>
>
>
>
> ___________________________________________________________
>
> *Ed Scott *|* **Microsoft Certified Solutions Developer (MCSD)*
>
> www: http://www.gencode.com
>
> emaill: escott at gencode.com
> Location:  Earth, Milkyway Galaxy
>
>
>
> *From:* monodroid-bounces at lists.ximian.com [mailto:
> monodroid-bounces at lists.ximian.com] *On Behalf Of *Craig Dunn
> *Sent:* Wednesday, March 16, 2011 12:07 AM
> *To:* monodroid at lists.ximian.com
> *Subject:* Re: [mono-android] WebView goes full screen when in tab layout
>
>
>
> Check out
> http://developer.android.com/resources/tutorials/views/hello-webview.html-- you need to add a custom WebViewClient subclass (see below).
> HTH
> Craig
>
>
> ------------------------------------------------------------------------------------
> using System;
>
> using Android.App;
> using Android.Content;
> using Android.OS;
> using Android.Views;
>
> using Android.Webkit;
>
> namespace MagshopDemo.Activities
> {
>     [Activity(Label = "Web View Example")]
>     public class WebActivity : BaseActivity
>     {
>         private WebView _browser;
>
>         protected override void OnCreate(Bundle bundle)
>         {
>             base.OnCreate(bundle);
>
>             SetContentView(Resource.Layout.Web);
>
>             var virtualPath = Intent.GetStringExtra("VirtualPath");
>
>             _browser = FindViewById<WebView>(Resource.Id.browser);
>             _browser.Settings.JavaScriptEnabled = true;
>             _browser.SetWebViewClient(new CustomWebViewClient());
>             _browser.LoadUrl(@"http://www.server.com/" + virtualPath);
>         }
>
>         public override void OnBackPressed()
>         {
>             if (_browser.CanGoBack())
>             {
>                 _browser.GoBack();
>             }
>             else
>             {
>                 base.OnBackPressed();
>             }
>         }
>     }
>
>     public class CustomWebViewClient : WebViewClient
>     {
>         public CustomWebViewClient()
>             : base()
>         { }
>
>         public override void OnPageStarted(WebView view, string url,
> Android.Graphics.Bitmap favicon)
>         {
>             base.OnPageStarted(view, url, favicon);
>         }
>
>         public override bool ShouldOverrideUrlLoading(WebView view, string
> url)
>         {   //
> http://developer.android.com/resources/tutorials/views/hello-webview.html
>             view.LoadUrl(url);
>             return true;
>         }
>     }
> }
>
> ------------------------------------------------------------------------------------
>
>
>
>
> On Wed, Mar 16, 2011 at 2:43 PM, <www at gencode.com> wrote:
>
> I made an app using the tab  layout example
>
>
>
> The example uses TextViews
>
> I simply changed the textview to webview
>
> As shown below, but I did not get an embedded webview inside the tabs as
> expected like the textview does, instead I got a full screen browser
>
>
>
>         protected override void OnCreate(Bundle bundle)
>
>         {
>
>             base.OnCreate(bundle);
>
>
>
>             WebView web_view = new WebView(this);
>
>             web_view.Settings.JavaScriptEnabled = true;
>
>             web_view.LoadUrl("http://www.google.com");
>
>             SetContentView(web_view);
>
>         }
>
>
>
>
>
> ___________________________________________________________
>
> *Ed Scott *|* **Microsoft Certified Solutions Developer (MCSD)*
>
> www: http://www.gencode.com
>
> emaill: escott at gencode.com
> Location:  Earth, Milkyway Galaxy
>
>
>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110317/390ec0f1/attachment.html 


More information about the Monodroid mailing list