![](/img/trans.png)
[英]In Android, I'm Trying to Fetch Data From a URL To Plot on a Map, but I'm Having Problems Even Getting it To Print
[英]Keyboard not getting dismissed even I'm trying to dismiss Android
我有一個editText,當我單擊“取消”時有兩個按鈕,我禁用了編輯文本並隱藏了鍵盤。
case R.id.verify_cancel:
hideMobileNoEditOption();
showAndHideError(verify_layout, false);
showAndHideError(mobile_error_tv, false);
mobile_number_et.clearFocus();
這是hideMobileNoEditOption()的代碼;
mobile_number_et.clearFocus();
AppUtil.hideSoftKeyboard(this);
mobile_number_et.setCursorVisible(false);
mobile_number_et.setFocusable(false);
mobile_number_et.setEnabled(false);
mobile_number_et.setTextIsSelectable(false);
mobile_number_et.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.zero_title));
這是隱藏鍵盤的代碼。
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (null != activity.getCurrentFocus()) {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
但是我的鍵盤並沒有因為上帝知道的原因而被解雇,任何人都可以幫忙嗎? 提前致謝
試試這個,這段代碼對我有用
/**
* For Hiding the keyboard
*/
public void hideKeyboard() {
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.