Android force eject, hide IME.

Source: Internet
Author: User

When we pop up a dialog time, if this dialog need to input data, and then determine the need to close the input method, the general system of hide, with the show method will always have a variety of problems, the most overbearing solution is to write a timer, timed pop-up or turn off the input method.

ImportJava.util.Timer;ImportJava.util.TimerTask;ImportAndroid.content.Context;ImportAndroid.view.View;ImportAndroid.view.inputmethod.InputMethodManager;ImportAndroid.widget.EditText; Public classInputtools {//Hide Virtual keyboard       Public Static voidHidekeyboard (View v) {Inputmethodmanager Imm=(Inputmethodmanager) V.getcontext (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {Imm.hidesoftinputfromwindow (), V.getapplicationwindowtoken (),0 ); }          }            //Show Virtual keyboard       Public Static voidShowkeyboard (View v) {Inputmethodmanager Imm=(Inputmethodmanager) V.getcontext (). Getsystemservice (Context.input_method_service);              Imm.showsoftinput (v,inputmethodmanager.show_forced); }            //force display or shutdown of the system keyboard       Public Static voidKeyBoard (FinalEditText Txtsearchkey,FinalString status) {Timer Timer=NewTimer (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {Inputmethodmanager m=(Inputmethodmanager) Txtsearchkey.getcontext (). Getsystemservice (Context.input_method_service); if(Status.equals ("open") {m.showsoftinput (txtsearchkey,inputmethodmanager.show_forced); }             Else{M.hidesoftinputfromwindow (Txtsearchkey.getwindowtoken (),0); }         }           }, 300); }            //force hidden virtual keyboard via timer       Public Static voidTimerhidekeyboard (FinalView v) {Timer Timer=NewTimer (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {Inputmethodmanager IMM=(Inputmethodmanager) V.getcontext (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {Imm.hidesoftinputfromwindow (V.getapplicationwindowtoken ()), 
    0 ); }             }          }, 10); }      //does the IME show       Public Static BooleanKeyBoard (EditText EditText) {BooleanBOOL =false; Inputmethodmanager IMM=(Inputmethodmanager) Edittext.getcontext (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {bool=true; }            returnbool; }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.