Hello njsokalski,
Welcome to our Microsoft Q&A platform!
To check whether the keyboard is open, try adding OnLayoutChangeListener
for the root layout of the Activity. If the height of the Activity pushed up exceeds 1/3 of the screen height, we can conside the soft keyboard has popped up.
Here is the sample code, you could refer to it.
public class TestActivity : AppCompatActivity, View.IOnLayoutChangeListener
{
protected override void OnCreate(Bundle savedInstanceState)
{
...
var layout = FindViewById<RelativeLayout>(Resource.Id.root);
keyHeight = this.WindowManager.DefaultDisplay.Height / 3;
layout.AddOnLayoutChangeListener(this);
}
int keyHeight = 0;
public void OnLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
{
//If the height of the activity pushed up exceeds 1/3 of the screen height, the soft keyboard can be considered to be up
if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight))
{
//the keyboard is open
}
else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight))
{
//the keyboard is closed
}
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.