WindowSoftInputMode doesn't work in Xamarin Forms Android

I work with XamarinForms and has some issues with Entry in ScrollView on Android platform. Autoscroll doesn't work correctly when I focuse on an entry placed in ScrollView. Entry appears above the keyboard but the whole page becomes unscrollable (I can't scroll completely to bottom or top of page). I try to set WindowSoftInputMode to adjustPan or adjustResize or both, and I try different ways to set it (in code, by attribute, directly in AndroidManifest.xml). But any case doesn't work (in each cases behavior remain the same). Please, maybe someone have encountered the same problem and I hope can help me. Thanks a lot.


  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai


    ScrollView has no affect on Android for scrolling when the keyboard is present. Instead, you will want to set the following in your MainActivity.OnCreate.


    There might be additional problems because of an Android bug. I found a solution to that on Adam Pedleys site.

    public class AndroidBug5497WorkaroundForXamarinAndroid
        // For more information, see
        // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
        // CREDIT TO Joseph Johnson ( for publishing the original Android solution on
        public static void assistActivity(Activity activity)
            new AndroidBug5497WorkaroundForXamarinAndroid(activity);
        private Android.Views.View mChildOfContent;
        private int usableHeightPrevious;
        private FrameLayout.LayoutParams frameLayoutParams;
        private AndroidBug5497WorkaroundForXamarinAndroid(Activity activity)
            FrameLayout content = (FrameLayout)activity.FindViewById(Android.Resource.Id.Content);
            mChildOfContent = content.GetChildAt(0);
            ViewTreeObserver vto = mChildOfContent.ViewTreeObserver;
            vto.GlobalLayout += (object sender, EventArgs e) => {
            frameLayoutParams = (FrameLayout.LayoutParams)mChildOfContent.LayoutParameters;
        private void possiblyResizeChildOfContent()
            int usableHeightNow = computeUsableHeight();
            if (usableHeightNow != usableHeightPrevious)
                int usableHeightSansKeyboard = mChildOfContent.RootView.Height;
                int heightDifference = usableHeightSansKeyboard - usableHeightNow;
                frameLayoutParams.Height = usableHeightSansKeyboard - heightDifference;
                usableHeightPrevious = usableHeightNow;
        private int computeUsableHeight()
            Rect r = new Rect();
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                return (r.Bottom - r.Top);
            return r.Bottom;

    Use it after the SetSoftInputMode line:


    The site from the link above also has an example renderer to disable the full screen behavior in landscape.

  • Hi @JohnMiller , thank you for answer. I have tried this solution before. And it doesn't work correctly with ScrollView in my case.
    I have to use ScrollView, because I have a lot of dynamic data in the page. Although this solution works well in Samsung device, but not LG.
    However when I override method RequestChildFocus for ScrollViewRenderer and do not call base.RequestChildFocus the bug goes away, but appears issue with numeric Entry (it stops working). So this solution doesn't solve my issue. I know that this problem can be solved in native Android by WindowSoftInputMode .
    Maybe you know some another solution which will work with scrollView.

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai


    Sorry that didn't help! If you have a sample or project you can share that could demostrate the issue you are having on a specific device, please add a bug report on Bugzilla and attach it. Feel free to ping me with the bug number and I will take a look at the project. Please follow the bug writing guidelines when reporting an issue.

  • AlexanderSheetyAlexanderSheety RUMember ✭✭


    UWP has the same problem !

    Do you have any solutions for UWP ?

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai


    Yep! There is a solution in the link I posted in my comment.

  • AlexanderSheetyAlexanderSheety RUMember ✭✭


    My investigations at Android:
    This solution doesn't work if entry is inside scrollview! View doesn't resize correctly!
    I tested StackLayout,AbsoluteLayout as topmost page layout. I hadn't results!
    But i finded some interesting in Grid. Entry inside scrollview works if Grid is topmost page layout!
    I don't know why only grid, but it is worked!

    Work Sample:

    >! using Xamarin.Forms.PlatformConfiguration;
    >! using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
    >! public class App : Xamarin.Forms.Application
    >! {
    >! public App()
    >! {
    >!           this.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
    >!          var stack = new Grid
    >!           {
    >!                   HorizontalOptions = LayoutOptions.FillAndExpand,
    >!                   VerticalOptions = LayoutOptions.FillAndExpand,
    >!                   RowDefinitions =
    >!                   {
    >!                           new RowDefinition { Height = 62 },
    >!                           new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
    >!                    },     
    >!            };
    >!       var boxmenu=new BoxView{
    >!           BackgroundColor = Color.Black;
    >!           HorizontalOptions = LayoutOptions.FillAndExpand;
    >!                   VerticalOptions = LayoutOptions.FillAndExpand;
    >!       };
    >!       var topmenubar=new AbsoluteLayout{
    >!           HorizontalOptions = LayoutOptions.FillAndExpand;
    >!                   VerticalOptions = LayoutOptions.FillAndExpand;
    >!                   Children={
    >!               {boxmenu, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All},
    >!       }
    >!       };
    >!       stack.Children.Add(topmenubar,0,0);
    >!       var scrollstack=new StackLayout{
    >!           HorizontalOptions = LayoutOptions.FillAndExpand;
    >!                   VerticalOptions = LayoutOptions.Start;
    >!                   BackgroundColor = Color.White;
    >!                   Spacing = 0;
    >!                   Padding = new Thickness(10,0,10,10);
    >!       };
    >!       for (int i=0;i<10;i++)
    >!       {
    >!           var label = new Label {
    >!                       FontSize=15,
    >!                       Text ="Label"+i,
    >!                       TextColor = Color.Black,
    >!                       HorizontalOptions = LayoutOptions.Start,
    >!                       VerticalOptions = LayoutOptions.Start,
    >!               Margin= new Thickness(0,10,0,0);
    >!           };
    >!           var entry = new Entry {
    >!               HorizontalOptions = LayoutOptions.Start,
    >!                       VerticalOptions = LayoutOptions.Start,
    >!                       BackgroundrColor=Color.FromRgb(240,240,240),
    >!                       TextColor=Color.Black,
    >!                       FontSize= 15,
    >!               };
    >!           scrollstack.Children.Add(label);
    >!           scrollstack.Children.Add(entry);
    >!            };
    >!       var scroll=new ScrollView{
    >!           Content=scrollstack,
    >!       };
    >!           stack.Children.Add(scroll,0,1);
    >!           MainPage = stack;
    >! }
    >! protected override void OnStart()
    >! {
    >!       // Handle when your app starts
    >! }
    >! protected override void OnSleep()
    >! {
    >!       // Handle when your app sleeps
    >! }
    >! protected override void OnResume()
    >! {
    >!       // Handle when your app resumes
    >! }
    >! }

    My investigations at UWP:
    This solution doesn't work if entry is inside scrollview! View doesn't resize correctly!

    Questions (Android and UWP ):

    1. How can i stop resize or pan view after showing keyboard ?
    2. How can i get keyboard height for calculations scroll height? ( I want to send scroll event to my scrollview )
  • Shane000Shane000 USMember ✭✭✭
    edited June 2017
  • ChrisHanChrisHan USMember ✭✭
    edited July 2017

    @JohnMiller: Workaround works fine, thanks! I chose the alternative method on Adams site, it is shorter and does not require creating another class.

  • ceddyceddy Member

    I've applied the workaround mentioned by @JohnMiller, which caused a new Problem:

    If I focus an input field at the bottom of the scroll view there is an empty space between the bottom of the ScrollView and the keyboard. Besides that, the Appbar and the very first element inside the ScrollView disappears completely. It looks like the whole View of the App is moved outside the display bounds.

    Has anybody an idea what went wrong?



  • muffadalkpmuffadalkp Member ✭✭


    The following workaround as per the link provided by you doesn't work for Android 8.0 (Oreo) on LG G7+ ThinQ phone.


    Any idea on what could be the reason and how can I fix this problem?


Sign In or Register to comment.