This article describes the Android implementation pop-up keyboard code, is a very useful feature. The code is very concise. Share to everyone for your reference.
The specific function code is as follows:
?
12345678 |
Timer timer =
new Timer();
timer.schedule(
new TimerTask() {
@Override
public void run() {
InputMethodManager m = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(
0
, InputMethodManager.HIDE_NOT_ALWAYS);
}
},
300
);
|
I hope this article is helpful to the study of Android program design.
Other
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.
Import Java.util.Timer;
Import Java.util.TimerTask;
Import Android.content.Context;
Import Android.view.View;
Import Android.view.inputmethod.InputMethodManager;
Import Android.widget.EditText;
public class Inputtools {
Hide Virtual keyboard
public static void Hidekeyboard (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 void Showkeyboard (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 void KeyBoard (final EditText txtsearchkey,final String status)
{
Timer timer = new timer ();
Timer.schedule (New TimerTask () {
@Override
public void Run ()
{
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 void Timerhidekeyboard (Final View v)
{
Timer timer = new timer ();
Timer.schedule (New TimerTask () {
@Override
public void Run ()
{
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 Boolean KeyBoard (EditText EditText)
{
boolean bool = false;
Inputmethodmanager IMM = (Inputmethodmanager) edittext.getcontext (). Getsystemservice (Context.input_method_service) ;
if (Imm.isactive ())
{
BOOL = true;
}
return bool;
}
}
Android soft keyboard force eject, hide IME.