Get Soft Keyboard Height in Xamarin.Android, use ViewTreeObserver.IOnGlobalLayoutListener to listen for GlobalLayout Change event and calculate the change difference in root view before and after in order to get the height of keyboard. You can do similar in Native Android Code.
here is the code:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
public static Android.Views.View RootView = null;
public void DetectSoftKeyboardHeight()
{
RootView = this.FindViewById(Android.Resource.Id.Content);
if(RootView!=null)
RootView.ViewTreeObserver.AddOnGlobalLayoutListener(new MyLayoutListener());
}
}
/// <summary>
/// My layout listener.
/// Detect Android Soft keyboard height
/// </summary>
public class MyLayoutListener : Java.Lang.Object, ViewTreeObserver.IOnGlobalLayoutListener
{
public void OnGlobalLayout()
{
// do stuff here
Android.Graphics.Rect r = new Android.Graphics.Rect();
if (Mobibranch.Droid.MainActivity.RootView != null)
{
Mobibranch.Droid.MainActivity.RootView.GetWindowVisibleDisplayFrame(r);
int screenHeight = Mobibranch.Droid.MainActivity.RootView.RootView.Height;
int keyboardHeight = screenHeight - (r.Bottom);
if (keyboardHeight > 0)
{
//Keyboard is up on screen
Android.Util.Log.Verbose("[[[[MyLayoutListener]]]]", "Keyboard is up on screen, Height: "+keyboardHeight);
}
else
{
//Keyboard is hidden
}
}
}
}