There is an edit box in the recent project, and the following is a ListView. After triggering the edit box to eject the soft keyboard, the ListView can also slide, and the ListView item can also respond to a click. This kind of experience is not effective. Then you want to see if the keyboard pops up when you swipe or click Item, and then hide it if it pops up.
Online search, found that Android does not directly provide a soft keyboard pop-up and hidden judgment, some solutions such as judging the height of the parent control or judgment
if (GetWindow (). GetAttributes (). Softinputmode==windowmanager.layoutparams.soft_input_state_hidden) hide the keyboard;
method does not work, so start with the official documentation.
Discover Inputmethodmanager has a method isactive (view view): Returns True if view is an 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)) Hide Keyboard
However, after the first pop-up keyboard and other touch operations, the keyboard did disappear. But at this point another touch operation (i.e. click on item), the input of view is still active. Because the Click event of item in my Code is
public void Onitemclick (...) { if (isActive (EditText)) { hide keyboard }else{ other Actions }}
So my item's other operations were not executed. Then look at the Inputmethodmanager function and find a function restartinput (view view): If the current input method is connected to the view, restart the IME with the new content. Restart? Then the input method of view will become the default inactive? So I added this function behind the hidden input method, and sure enough, it succeeded.
This method is relatively simple, the code is short, also very good understanding, hope to help people in need, nor waste my commissioning a few hours of kung fu.
Attached code:
Inputmethodmanager Inputmethodmanager = (Inputmethodmanager) getactivity (). Getsystemservice (Context.INPUT_METHOD_ SERVICE);
Private Boolean Hidekeyboard () {if (inputmethodmanager.isactive (Searchedittext)) {
Android to judge the soft keyboard pop-up and hide the simple perfect solution