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

前端 未结 10 623
无人及你
无人及你 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:39

    In your XML file inside your edittext tag add below snippet

    android:imeOptions="actionDone"
    

    Then inside your Java class, write the below code

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

提交回复
热议问题