Before I also encountered a problem about getting a soft keyboard state, on the internet to find a lot of information, basically the answer is to use GetWindow (). GetAttributes (). softinputmode== WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED to determine if the soft keyboard is open, if the equality is open, then you can follow this code for subsequent operations. But I tried for a long time, whether the soft keyboard pops up or closes the GetWindow (). GetAttributes (). The value of Softinputmode is always 0, as for why the value has been 0 I don't know,
But then I found a new way to fix it:
Create a Inputmethodmanager object directly, Inputmethodmanager IMM = (Inputmethodmanager) context.getsystemservice (context. Input_method_service), by means of the IsActive () method of the object, Imm. IsActive () If put back to true, the state of the soft keyboard is open, then it is good to do, directly according to IMM. IsActive () Return status for subsequent operations (close the soft keyboard),
The code is as follows:
public void Hideinputwindow {
if (context==null) {return
;
}
Final View v = ((activity) context). GetWindow (). Peekdecorview ();
if (v!= null && v.getwindowtoken ()!= null) {
Inputmethodmanager IMM = (inputmethodmanager) context.getsystem Service (context. Input_method_service);
Imm.hidesoftinputfromwindow (V.getwindowtoken (), 0);
}
}
The above is small series for everyone to bring the Android to judge the status of soft keyboard and hide the simple example of a soft keyboard all content, I hope that we support the cloud Habitat Community ~