Welcome to the CSDN-markdown Editor, csdn-markdown

Source: Internet
Author: User

Welcome to the CSDN-markdown Editor, csdn-markdown
Android Edittext hides the keyboard popped up by the system and displays the light indicator.

When Android. edittext is clicked, the keyboard popped up by the system is hidden and the light indicator is displayed.

Android shields the system keyboard because it uses a self-created virtual big keyboard. However, in the 4.1 Test System, editText is used. setInputType (InputType. TYPE_NULL) the method can hide the keyboard, but the cursor is also hidden, so it cannot be used.
In versions earlier than 3.0, editText. setInputType (InputType. TYPE_NULL) can be used. Alternatively, you can set editText. setKeyListener (null.
In Versions later than 3.0, besides calling the hidden method: setShowSoftInputOnFocus (false), because it is an internal method of the system. It cannot be called directly, so the reflection method is used for calling, as shown below>

Code block

Java code block:

/*** Hide the system keyboard Edittext. Do not display the system keyboard. There must be a cursor. If TYPE_NULL is greater than 4.0, the system keyboard is not displayed, but the cursor is gone; */public void hideSoftInputMethod (EditText ed) {getWindow (). setSoftInputMode (WindowManager. layoutParams. SOFT_INPUT_STATE_ALWAYS_HIDDEN); int currentVersion = android. OS. build. VERSION. SDK_INT; String methodName = null; if (currentVersion> = 16) {// 4.2 methodName = "setShowSoftInputOnFocus"; // 19 setShowSoftInputOnFocus} else if (currentVersion> = 14) {// 4.0 methodName = "setSoftInputShownOnFocus";} if (methodName = null) {ed. setInputType (InputType. TYPE_NULL);} else {Class <TextView> cls = TextView. class; java. lang. reflect. method setShowSoftInputOnFocus; try {setShowSoftInputOnFocus = cls. getMethod (methodName, boolean. class); setShowSoftInputOnFocus. setAccessible (true); setShowSoftInputOnFocus. invoke (ed, false);} catch (Exception e) {ed. setInputType (InputType. TYPE_NULL); e. printStackTrace ();}}}

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.