Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Toolbar goes up when keyboard opens xamarin forms

I want to keep toolbar visible on top while displaying soft keyboard. I tried all options with windowSoftInputMode but non of them worked. This has started occurring after upgrading xamarin forms to 2.3.4.247. It was working fine previously.

Before xamarin forms update Previous result

After xamarin forms update result

Best Answer

  • AmitThakkarAmitThakkar INMember ✭✭
    Accepted Answer

    Below code solved my issue.

    Ref: https://gist.github.com/jimmgarrido/e36033b26f01e8da091fd321d41d991a

    protected override void OnCreate(Bundle bundle)
        {
            ToolbarResource = Resource.Layout.toolbar;
    
            base.OnCreate(bundle);
    
            //Remove the status bar underlay in API 21+
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.DecorView.SystemUiVisibility = 0;
                var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                statusBarHeightInfo.SetValue(this, 0);
                Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
            }
    
    
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
    
            App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
        }
    

Answers

  • AmitThakkarAmitThakkar INMember ✭✭
    Accepted Answer

    Below code solved my issue.

    Ref: https://gist.github.com/jimmgarrido/e36033b26f01e8da091fd321d41d991a

    protected override void OnCreate(Bundle bundle)
        {
            ToolbarResource = Resource.Layout.toolbar;
    
            base.OnCreate(bundle);
    
            //Remove the status bar underlay in API 21+
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.DecorView.SystemUiVisibility = 0;
                var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                statusBarHeightInfo.SetValue(this, 0);
                Window.SetStatusBarColor(new Android.Graphics.Color(18, 52, 86, 255));
            }
    
    
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
    
            App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
        }
    
  • N_BauaN_Baua INMember ✭✭✭✭✭

    @AmitThakkar said:
    I want to keep toolbar visible on top while displaying soft keyboard. I tried all options with windowSoftInputMode but non of them worked. This has started occurring after upgrading xamarin forms to 2.3.4.247. It was working fine previously.

    Before xamarin forms update Previous result

    After xamarin forms update result

    can you re-produce and log it as a bug, so Xamarin guys can look in to it and fix the same.

  • AmitThakkarAmitThakkar INMember ✭✭
    edited August 2017
  • kennepalkennepal Member

    I have entered the 'fix' code as above, but keep getting a 'SYSTEM.NULLREFERENCEEXCEPTION' on the line: statusBarHeightInfo.SetValue(this,0);

Sign In or Register to comment.