WindowSoftInputModeAdjust.Resize doesn't work with Xamarin.Forms Shell Page

Muthu kumaran 21 Reputation points
2020-12-08T20:18:29.313+00:00

Greetings.

I am facing an issue in android platform with focusing an entry at the bottom of the page in shell Page. When the keyboard gets layout on the screen it pushes all the items in the view above which is actually fine until it scrolls the TitleBar or NavigationBar too! This case is similar to the below issue.

https://github.com/xamarin/Xamarin.Forms/issues/4273

So I have tried using WindowSoftInputModeAdjust.Resize as an workaround. But it doesn't work inside shell page. I have modified and attached the shell demo sample which replicates the issue. Can you let me know whether any work around available for this issue as of now?

Please find the issue replication sample in the below issue.
https://github.com/xamarin/Xamarin.Forms/issues/13083

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,357 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,001 Reputation points Microsoft Vendor
    2020-12-09T07:10:54.59+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Do you not want to hide the navigatebar when keyboard popup like this screenshot?

    46369-image.png

    If so, It is native android's know issue. You can try to use following workaround. Add following code to your MainActivity.cs

       public class AndroidBug5497WorkaroundForXamarinAndroid  
           {  
         
               // For more information, see https://code.google.com/p/android/issues/detail?id=5497  
               // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.  
         
               // CREDIT TO Joseph Johnson (http://stackoverflow.com/users/341631/joseph-johnson) for publishing the original Android solution on stackoverflow.com  
         
               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) => {  
                       possiblyResizeChildOfContent();  
                   };  
                   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;  
         
                       mChildOfContent.RequestLayout();  
                       usableHeightPrevious = usableHeightNow;  
                   }  
               }  
         
               private int computeUsableHeight()  
               {  
                   Rect r = new Rect();  
                   mChildOfContent.GetWindowVisibleDisplayFrame(r);  
                   if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)  
                   {  
                       return (r.Bottom - r.Top);  
                   }  
                   return r.Bottom;  
               }  
           }  
    

    Then use it in your OnCreate() method

       protected override void OnCreate(Bundle savedInstanceState)  
               {  
                   TabLayoutResource = Resource.Layout.Tabbar;  
                   ToolbarResource = Resource.Layout.Toolbar;  
         
                   base.OnCreate(savedInstanceState);  
                   Window.SetStatusBarColor(Android.Graphics.Color.Argb(255, 0, 0, 0));  
         
                   this.Window.SetSoftInputMode(SoftInput.AdjustResize);  
                   AndroidBug5497WorkaroundForXamarinAndroid.assistActivity(this);  
         
         
                  global::Xamarin.Forms.Forms.Init(this, savedInstanceState);  
                   Xamarin.Essentials.Platform.Init(this, savedInstanceState);  
                   LoadApplication(new App());  
               }  
    

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.