Before I also encountered a question 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 solution: directly create a Inputmethodmanager object, 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 (turn off the soft keyboard), the code is as follows:
public void Hideinputwindow {
if (context==null) {
& nbsp return;
 }&NBSP
final View v = ((activity) context). GetWindow (). Peek Decorview ();
if (v!= null && v.getwindowtoken ()!= null) {
&NBSP ; inputmethodmanager IMM = (Inputmethodmanager) context.getsystemservice (context. Input_method_service);
imm.hidesoftinputfromwindow (V.getwindowtoken (), 0);
}
 }