Android detect Done key press for OnScreen Keyboard

后端 未结 3 2009
渐次进展
渐次进展 2020-11-27 14:21

Is it possible to detect when the Done key of onScreen keyboard was pressed ?

3条回答
  •  无人及你
    2020-11-27 15:05

    Yes, it is possible:

    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;
        }
    });
    

    Note that you will have to import the following libraries:

    import android.view.KeyEvent;
    import android.view.inputmethod.EditorInfo;
    import android.widget.TextView;
    

提交回复
热议问题