我正在开发android。在我的登录页面中,我有一个提交按钮,它工作正常。现在我需要让Android键盘“完成”按钮操作具有相同的提交按钮功能。我怎样才能做到这一点?任何帮助都会提前感谢。
答案 0 :(得分:5)
您需要为Edittext实施OnEditorActionListener
。喜欢
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
//TODO: do something
}
return false;
}
});
答案 1 :(得分:1)
这是我发现的
class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
}
源:
你应该做更多的谷歌搜索
答案 2 :(得分:0)
使用OnEditorActionListener
EditText edit = (EditText)findViewById(R.id.edit);
edit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i("check","Enter pressed");
}
return false;
}
});