android--Click EditText when the soft keyboard pop-up, click the edittext outside the blank soft keyboard disappears

Source: Internet
Author: User

The soft keyboard pops up when you click EditText on Android, but when we've entered or want to hide the soft keyboard, we can click the Hide button on the soft keyboard, which is possible, but in order to improve the user experience, We often want to achieve this function: when you want to hide the soft keyboard after the input, we can hide the soft keyboard by directly clicking the other space outside the EditText, which is significantly more convenient than clicking on the soft Keyboard's own hidden button.

To implement the above functions simply rewrite the public boolean ontouchevent (Motionevent event) method, do the corresponding soft keyboard hidden processing operations.

Inputmethodmanager imm=(Inputmethodmanager) Getsystemservice (Context.input_method_service); @Override Public Booleanontouchevent (Motionevent event) {//TODO auto-generated Method Stub        if(event.getaction () = =Motionevent.action_down) {  if(MyActivity. This. Getcurrentfocus ()! =NULL) {                  if(MyActivity. This. Getcurrentfocus (). Getwindowtoken ()! =NULL) {Imm.hidesoftinputfromwindow (myactivity. This. Getcurrentfocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); }              }          }          return Super. Ontouchevent (event); }  

android--Click EditText when the soft keyboard pop-up, click the edittext outside the blank soft keyboard disappears

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.