問題描述
我使用了一些 Android 代碼來覆蓋 EditText 字段中的完成"按鈕:
I have used a bit of Android code to override the "Done" button in my EditText field:
myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
mySubroutine();
return true;
}
return false;
}
});
激活該字段會調用鍵盤,然后按完成"會成功評估 mySubroutine().但是,當我按下完成"時,鍵盤不再消失.如何將此默認行為恢復為例程?
Activating the field calls up the keyboard, and pressing "Done" evaluates mySubroutine() successfully. However, the keyboard no longer goes away when I press "Done". How do I restore this default behaviour to the routine?
推薦答案
為什么不呢:
myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
mySubroutine();
}
return false;
}
});
在處理完代碼后返回 false.這可以解釋為無論您的代碼 (mySubroutine()) 做什么,之后它仍將使用默認操作.如果您返回true",則說明您是一個快樂的編碼員,需要完成的所有事情都在您的 mySubroutine() 中發生,并且默認操作不需要執行.
Just return false after you handle your code. This can be interpreted as no matter what your code (mySubroutine()) does it will still use the default action afterwards. If you return "true" you are telling that you are a happy coder and everything that needed to be done has happen in your mySubroutine() and the default action do not need to take action.
這篇關于Android:將鍵盤隱藏在覆蓋的“完成"中EditText 的按鍵的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!