Android Click to close the soft keyboard

Source: Internet
Author: User

In the project, the EditText will automatically eject the soft keyboard when the focus is taken, and when you close it, you usually need to press the back key or click the button on the soft keyboard.

Even if the current activity has been completed, the soft keyboard still exists, affecting the user's experience.

Online There are many very detailed methods, such as clicking on other blank areas, the soft keyboard will disappear and the like, we do not require this project, the requirements are as long as

Do not block other operations, and the current activity is closed after the soft keyboard disappears on the line,

Today we share two ways:

This method, if displayed, is hidden if hidden then shows private void Hintkbone () {Inputmethodmanager IMM = (Inputmethodmanager) getactivity (). Getsystemservice (context.input_method_service);  Get an instance of Inputmethodmanager if (imm.isactive ()) {//If you turn on Imm.togglesoftinput (Inputmethodmanager.show_implicit, inputmethodmanager.hide_not_always);}    }

This method just turns off the soft keyboard private void Hintkbtwo () {Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (context.input_ Method_service);  if (Imm.isactive () &&getcurrentfocus ()!=null) {if (Getcurrentfocus (). Getwindowtoken ()!=null) { Imm.hidesoftinputfromwindow (Getcurrentfocus (). Getwindowtoken (), inputmethodmanager.hide_not_always);}}}   

Just call the method when you need to click on the event to close the soft keyboard.

Forwarding please indicate address http://blog.csdn.net/jing110fei/article/details/41863821

PS: If someone forwards it,

Android Click to close the soft keyboard

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.