1 Packagecom.xdsjs.save.utils;2 3 ImportAndroid.content.Context;4 ImportAndroid.view.inputmethod.InputMethodManager;5 ImportAndroid.widget.EditText;6 7 ImportJava.util.Timer;8 ImportJava.util.TimerTask;9 Ten /** One * Turn the soft keyboard on or off A * - * @authorXdsjs - */ the Public classKeyboardutils { - /** - * Punch the soft keyboard - * + * @parammedittext Input Box - * @paramMcontext Context + */ A Public Static voidOpenkeybord (FinalEditText Medittext,FinalContext Mcontext) { at - //You have to wait for the UI drawing to finish, and the code to open the soft keyboard will take effect, so set a delay -Timer timer =NewTimer (); -Timer.schedule (NewTimerTask () { - @Override - Public voidrun () { inInputmethodmanager IMM =(Inputmethodmanager) Mcontext - . Getsystemservice (context.input_method_service); to imm.showsoftinput (Medittext, inputmethodmanager.result_shown); + imm.togglesoftinput (inputmethodmanager.show_forced, - inputmethodmanager.hide_implicit_only); the } *}, 500); $ }Panax Notoginseng - /** the * Turn off the soft keyboard + * A * @parammedittext Input Box the * @paramMcontext Context + */ - Public Static voidClosekeybord (EditText medittext, Context mcontext) { $Inputmethodmanager IMM =(Inputmethodmanager) Mcontext $ . Getsystemservice (context.input_method_service); - -Imm.hidesoftinputfromwindow (Medittext.getwindowtoken (), 0); the } -}
Keyboardutils.java--android Keyboard Tool class