Среда
Версия Android: Android 16 (API 35)
Версия Xamarin.Forms: 5.0.0.2578
Что я пробовал (все не удалось):
- Пробовал AdjustResize, AdjustPan, AdjustNothing, StateAlwaysHidden
- Попытка принудительного обновления макета с помощью RequestLayout(), ForceLayout(), Invalidate()
- Отслеживается с помощью ViewTreeObserver.GlobalLayout().
Просмотр перед клавиатурой
Просмотр с помощью клавиатуры
Просмотр после скрытия клавиатуры
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;
}
Пользовательский рендерер:
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();
}
};
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... android-16
Мобильная версия