本文介紹了防止軟鍵盤被關閉的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
關于如何以編程方式顯示/隱藏軟鍵盤有很多問題.
There are many questions related to how to programatically show/hide the soft keyboard.
但是,眾所周知,android 后退按鈕會導致鍵盤被關閉.有沒有辦法防止用戶按下后退按鈕關閉鍵盤?
However, as we all know the android back button will cause the keyboard to be dismissed. Is there a way to prevent the user from dismissing the keyboard with a back button press?
我試圖捕獲后退按鈕,但是當鍵盤顯示時,我的活動中的 onKeyDown 不會在按下后退鍵并且軟鍵盤可見時被調用.
I tried to capture the back button, but when the keyboard is displayed onKeyDown in my activity is not invoked when the back key is pressed and soft keyboard is visible.
任何建議將不勝感激.
推薦答案
我找到了解決方案:
public class KeyBoardHolder extends EditText {
public KeyBoardHolder(Context context) {
super(context);
}
public KeyBoardHolder(Context context, AttributeSet attrs) {
super(context, attrs);
}
public KeyBoardHolder(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public KeyBoardHolder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return false;
}
}
這可以防止鍵盤被返回按鈕關閉.
This prevents keyboard from being closed by back button.
這篇關于防止軟鍵盤被關閉的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!