Keyboard Issue in Android 16 for Xamarin Application [duplicate]

2 weeks ago 14
ARTICLE AD BOX

I have a xamarin application and whenever it has an entry at the bottom where the keyboard appears it resizes and come above the keyboard so that I could see what I type but right after I complete typing when I click on done or tap outside the entry the keyboard tries to go down and the screen is trying to resize but it stucks in the middle of half way and a black screen appears in the bottom of screen leaving my screen black at half way of the keyboard.

Environment

Android Version: Android 16 (API 35)

Xamarin.Forms Version: 5.0.0.2578

What I've Tried (All Failed):

Tried AdjustResize, AdjustPan, AdjustNothing, StateAlwaysHidden

Tried forcing layout refresh with RequestLayout(), ForceLayout(), Invalidate()

Monitored with ViewTreeObserver.GlobalLayout().

But I cannot bring the original smooth Android 14 transition. I can still see a black screen for a second.

View before keyboard

View with Keyboard

View After Keyboard Hides

MainActivity.cs

private void RegisterKeyboardListener() { _rootView = Window.DecorView.RootView; _globalLayoutHandler = (sender, args) => { var rect = new Android.Graphics.Rect(); _rootView.GetWindowVisibleDisplayFrame(rect); int screenHeight = _rootView.Height; int keypadHeight = screenHeight - rect.Bottom; bool isKeyboardVisible = keypadHeight > screenHeight * 0.15; _rootView.Post(() => { _rootView.PostDelayed(() => { _rootView.RequestLayout(); _rootView.Invalidate(); }, 16); }); _keyboardWasVisible = isKeyboardVisible; }; _rootView.ViewTreeObserver.GlobalLayout += _globalLayoutHandler; }

Custom Renderer:

if (!e.HasFocus) { var rootView = MainActivity.Instance.Window.DecorView.RootView; rootView.ViewTreeObserver.GlobalLayout += (sender, args) => { var heightDiff = rootView.RootView.Height - rootView.Height; if (heightDiff < 200) // Keyboard is hidden { rootView.RequestLayout(); } }; }
Read Entire Article