1

我正在研究安卓。在我的登录页面中,我有一个提交按钮,它工作正常。现在我需要使 android 键盘“完成”按钮操作具有与提交按钮相同的功能。我怎样才能做到这一点?任何帮助将提前表示感谢。

4

3 回答 3

5

您需要OnEditorActionListener为 Editext 实施。喜欢

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;
    }
});
于 2013-05-31T10:38:14.647 回答
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;
}

}

资源:

http://savagelook.com/blog/android/android-quick-tip-edittext-with-done-button-that-c​​loses-the-keyboard

你应该做更多的谷歌搜索

于 2013-05-31T10:39:16.367 回答
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;
            }
        });
于 2013-05-31T10:43:26.667 回答