简体   繁体   中英

nativeOnDraw failed - Xamarin Android Webview

Im using xamarin for android and i have looked into this issue but nothing seems to work.

Im trying to get a webview to work with a button but it keeps saying whenever i click on the button.

nativeOnDraw failed; clearing to background color.

I will include image of my layout and my code here. 在此处输入图片说明

MainActivity

    namespace Application
{
    [Activity(Label = "Application", MainLauncher = true, Icon = "@drawable/icon", Theme = "@android:style/Theme.NoTitleBar")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            WebPage webPage = new WebPage();

            Button btn_MySchedule = FindViewById<Button>(Resource.Id.btnSchedule);
            Button btn_MyCareer = FindViewById<Button>(Resource.Id.btnCareer);
            Button btn_MySocial = FindViewById<Button>(Resource.Id.btnSocial);
            Button btn_Feedback = FindViewById<Button>(Resource.Id.btnFeedback);
            Button btn_MyDetails = FindViewById<Button>(Resource.Id.btnDetails);

            btn_MySchedule.Click += delegate
            {
                webPage.isSchedule = true;
                //wPage.SetUrl("https://www.google.com");
                StartActivity(typeof(WebPage));
            };
        }
    }
}

WebPage

namespace Application
{
    [Activity(Label = "WebPage", Theme = "@android:style/Theme.NoTitleBar")]
    public class WebPage : Activity
    {
        public bool isSchedule;

        private WebView _webView;
        private string _url;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.WebPage);

            _webView = FindViewById<WebView>(Resource.Id.webView);

            new DisplayWebPage(_webView, GetUrl());
        }

        public string GetUrl()
        {
            return _url;
        }

        public void SetUrl(string sUrl)
        {
            _url = sUrl;
        }

        private void ButtonCLicked()
        {
            if (isSchedule == true)
            {
                SetUrl("https://www.google.com");
                Toast.MakeText(this, "isSchedule is true", ToastLength.Short).Show();
            }
        }
    }
}

I have found the issue. It was due to me calling an empty string via the GetUrl() methods. The Solution I used is:

[Export("MyScheduleClicked")]
    public void MyScheduleClicked(View v)
    {
        var activity2 = new Intent(this, typeof(WebPage));

        activity2.PutExtra("MyURL", "https://www.google.com");

        StartActivity(activity2);
    }   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM