The soft keyboard pops up when you click EditText on Android, but when we've entered or want to hide the soft keyboard, we can click the Hide button on the soft keyboard, which is possible, but in order to improve the user experience, We often want to achieve this function: when you want to hide the soft keyboard after the input, we can hide the soft keyboard by directly clicking the other space outside the EditText, which is significantly more convenient than clicking on the soft Keyboard's own hidden button.
To implement the above functions simply rewrite the public boolean ontouchevent (Motionevent event) method, do the corresponding soft keyboard hidden processing operations.
Inputmethodmanager imm=(Inputmethodmanager) Getsystemservice (Context.input_method_service); @Override Public Booleanontouchevent (Motionevent event) {//TODO auto-generated Method Stub if(event.getaction () = =Motionevent.action_down) { if(MyActivity. This. Getcurrentfocus ()! =NULL) { if(MyActivity. This. Getcurrentfocus (). Getwindowtoken ()! =NULL) {Imm.hidesoftinputfromwindow (myactivity. This. Getcurrentfocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); } } } return Super. Ontouchevent (event); }
android--Click EditText when the soft keyboard pop-up, click the edittext outside the blank soft keyboard disappears