Handle enter key in EditText across different devices

前端 未结 3 1304
温柔的废话
温柔的废话 2021-02-14 11:07

Right now I\'m handling the enter key in my EditText fields using a an onEditorActionListener and looking at the Action ID for IME_NULL. It works fine for all my users except o

3条回答
  •  情深已故
    2021-02-14 11:36

    (EditText) passwordView = (EditText) findViewById(R.id.password);
    passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        passwordView.setOnEditorActionListener(new OnEditorActionListener()
            {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
                {
                    String input;
                    if(actionId == EditorInfo.IME_ACTION_DONE)
                    {
                       input= v.getText().toString();
                        Toast toast= Toast.makeText(LogIn.this,input,
                                Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                        return true;
                    }
                    return false;
                }
            });
    

提交回复
热议问题