4.0以上的API禁止EditText彈出鍵盤需要這樣寫:
4.0的是setShowSoftInputOnFocus,4.2的是setSoftInputOnFocus。
EditText?editText;//editText的實例化我不寫了
InputMethodManager?imm?=?(InputMethodManager)?getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(e1.getWindowToken(),?0);
try?{
Class<EditText>?cls?=?EditText.class;
setSoftInputShownOnFocus?=?cls.getMethod("setShowSoftInputOnFocus",?boolean.class);
setSoftInputShownOnFocus.setAccessible(true);
setSoftInputShownOnFocus.invoke(editText,?false);
}?catch?(Exception?e)?{
e.printStackTrace();
}
並且還要在配置文件裏面加上android:windowSoftInputMode="stateHidden"
4.0以下的可用editText.setInputType(InputType.TYPE_NULL);
或者直接在XML進行屬性設置。
如果對4.0以上系統的操作這句代碼,EditText將會沒有光標。