Android soft keyboard force eject, hide IME.

Source: Internet
Author: User

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.

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.