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

Craig Dunn craig.dunn at conceptdevelopment.net
Wed Mar 16 00:07:03 EDT 2011


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110316/a5348b60/attachment-0001.html 


More information about the Monodroid mailing list