-
-
Save fyhack/7333124 to your computer and use it in GitHub Desktop.
解决 sdk 4.0 以上屏蔽系统输入法以后不显示光标的Bug;
Shielding system soft keyboard does not display the EditText cursor Bug.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (android.os.Build.VERSION.SDK_INT <= 10) { //2.3版本之前使用此方法 | |
edit.setInputType(InputType.TYPE_NULL); | |
} else { //2.3版本以后用反射方法设置setSoftInputShownOnFocus(4.0)的值解决 | |
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); | |
try { | |
Class<EditText> cls = EditText.class; | |
Method setSoftInputShownOnFocus; | |
setSoftInputShownOnFocus = cls.getMethod("setSoftInputShownOnFocus", boolean.class); | |
setSoftInputShownOnFocus.setAccessible(true); | |
setSoftInputShownOnFocus.invoke(edit, false); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
try { // 有部分SDK的方法名字为setShowSoftInputOnFocus(4.2) | |
Class<EditText> cls = EditText.class; | |
Method setShowSoftInputOnFocus; | |
setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class); | |
setShowSoftInputOnFocus.setAccessible(true); | |
setShowSoftInputOnFocus.invoke(edit, false); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment