There is an edit box in the recent project, and the following is a ListView. After the trigger box pops up, the ListView can also slide and the ListView item will respond to the click. This experience is not very effective. So you want to slide or click the item to determine whether the keyboard pops up, if it pops up, hide it.
Online search, found that Android does not directly provide soft keyboard pop-up and hidden judgments, some solutions such as the height of the parent control or judge
if (GetWindow (). GetAttributes (). Softinputmode==windowmanager.layoutparams.soft_input_state_hidden)
hides the keyboard;
Method was not used, so the official document began.
Found Inputmethodmanager has a method isactive (view view): Returns True if view is the active view of the input method. That is, returns true if the soft keyboard is ejected by the view trigger. Wow, that's a good question.
if (IsActive (edittext))
hides the keyboard
Then let the other view force the focus, so that Isactivite (Ediitext) is false.
This method is relatively simple, the code is relatively short, also very good understanding, hope to be able to help people in need, nor waste I debug a few hours of kung fu.
Attached code:
Inputmethodmanager Inputmethodmanager = (Inputmethodmanager) getactivity (). Getsystemservice (Context.INPUT_METHOD_ SERVICE); <br>private boolean hidekeyboard () {
if (inputmethodmanager.isactive (Searchedittext)) {<br >//Because it is under fragment, GetView () is used to get view, or Findviewbyid () to get the parent control
GetView (). Requestfocus (); The other view gets the focus. This is because it is under the fragment, so we use GetView () to specify any other view
Inputmethodmanager.hidesoftinputfromwindow ( Getactivity (). Getcurrentfocus (). Getwindowtoken (), inputmethodmanager.hide_not_always);
return true;
}
return false;
}
PS: If it is a manual eject keyboard, getactivity () Getcurrentfocus () is changed to Searchedittext. and the manual eject keyboard Isactivie () is invalid and can be judged by the tag.
The above is a small series for everyone to bring the Android Judge soft keyboard pop-up and hide the simple perfect solution (recommended) All content, I hope that we support cloud-Habitat Community ~