Keyboard stays open after closing fragment

misko101misko101 HRMember ✭✭

Hi,
I have a very strange bug which I cant figure out how to solve. In MyActivity on button pressed fragment pops up, in which I have EditText, and when I close fragment with keyboard still opened, keyboard stays open in MyActivity. I have this lines in my OnCreate function of MyActivity:

if (savedInstanceState == null)
{
mEditText.RequestFocus();
Window.SetSoftInputMode(SoftInput.StateVisible);
}

mEditText is EditText in MyActivity, not fragment. If I comment Window.SetSoftInputMode(SoftInput.StateVisible); I dont have this happening, but I want to show keyboard on activity created. I manage to fix it when I press button in fragment with this:

InputMethodManager mgr = (InputMethodManager)Activity.GetSystemService(Context.InputMethodService);
mgr.HideSoftInputFromWindow(mEditTextFragment.WindowToken, 0);

However it doesnt work for pressing outside of fragment. If I try to put this in OnCancel() it doesnt work because fragment is already closed so it cant reach mEditTextFragment.WindowToken.
Does anyone have any idea how to solve this?

Best Answer

Answers

Sign In or Register to comment.