當前位置:編程學習大全網 - 網站源碼 - Android的EditText長按只顯示上面的復制粘貼菜單,不要彈出下面的輸入法鍵盤怎麽做?

Android的EditText長按只顯示上面的復制粘貼菜單,不要彈出下面的輸入法鍵盤怎麽做?

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將會沒有光標。

  • 上一篇:返利網為什麽可以返利?
  • 下一篇:導航unity支持2d嗎?
  • copyright 2024編程學習大全網