Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Keyboard stays open after closing fragment

$
0
0

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?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>