Android event triggers edittext focus and automatic pop-up keyboard

Source: Internet
Author: User
 

About the edittext focus and keyboard in Android:

Usually in a layout, set the focus mode for edittext as follows. After the activity is started, the focus is automatically positioned to the first edittext and the keyboard automatically pops up.

Method 1: In layout:

 
Android: focusable = "true" Android: focusableintouchmode = "true"

Method 2:CodeMedium:

 
Edit. setfocusable (true );

If you do not need to enable the automatic pop-up keyboard, set the property Android: windowsoftinputmode = "statealwayshidden" (or statehidden | adjustresize) in the activity tag of the manifest file)

Set as needed to prevent the keyboard from being automatically popped up.

But if you wantEvent triggeringTo bring up the keyboard (for example, when switching from voice to text), you need to bring up the keyboard automatically.

The specific method is as follows:

 
Edit. requestfocus (); inputmethodmanager Imm = (inputmethodmanager) EDIT. getcontext (). getsystemservice (context. input_method_service); Imm. togglesoftinput (0, inputmethodmanager. show_forced );

The above code consists of two parts: the first step is to get the focus through the requestfocus () method (setfocusable (true) does not know why it is invalid );

The second step is to force the keyboard to pop up. Because the focus is on edittext, the input is normal.

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.