Implicit “Submit” after hitting Done on the keyboard at the last EditText

前端 未结 10 615
无人及你
无人及你 2020-11-29 17:51

I\'ve used some apps where when I fill my username, then go to my password, if I hit \"Done\" on the keyboard, the login form is automatically submitted, without me having t

10条回答
  •  一整个雨季
    2020-11-29 18:19

    You need to set the IME Options on your EditText.

    
    

    Then add a OnEditorActionListener to the view to listen for the "done" action.

    EditText editText = (EditText) findViewById(R.id.some_view);
    editText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                // TODO do something
                handled = true;
            }
            return handled;
        }
    });
    

    Official API doc: https://developer.android.com/guide/topics/ui/controls/text.html#ActionEvent

提交回复
热议问题