Answers:
是的,有可能:
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do your stuff here
}
return false;
}
});
请注意,您将必须导入以下库:
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
当您必须处理Android应用程序中的任何类型的用户输入时,Editor Info是最有用的类。例如,在登录/注册/搜索操作中,我们可以将其用于更准确的键盘输入。编辑器信息类描述了文本编辑对象的几个属性,输入方法将直接与编辑文本内容进行通信。
您可以尝试使用IME_ACTION_DONE。
此操作将执行任何Done操作而无需输入任何内容,并且IME将被关闭。
EditTextObj.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
/* Write your logic here that will be executed when user taps next button */
handled = true;
}
return handled;
}
});
使用黄油刀可以做到这一点
@OnEditorAction(R.id.signInPasswordText)
boolean onEditorAction(TextView v, int actionId, KeyEvent event){
if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
/* Write your logic here that will be executed when user taps next button */
}
return false;
}
EditorInfo.IME_ACTION_SEARCH镜头搜索按钮。