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 ();}}}