android EditText 监听

android EditText 回车事件
对于非内置输入法

password = (EditText) findViewById(R.id.login_password_edit);
  password.setOnKeyListener(new OnKeyListener() {

   @Override
   public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_ENTER == keyCode && event.getAction() == KeyEvent.ACTION_DOWN) {
     login();
     return true;
    }
    return false;

   }
  });


内置输入法

 <EditText
            android:id="@+id/login_password_edit"
            android:layout_width="wrap_content"
android:imeOptions="actionSend" />

或者

editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

会根据imeOptions值得不同,默认输入法的回车键会有不同的图案和功能。
https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html

代码里监听

password.setOnEditorActionListener(new TextView.OnEditorActionListener() {

   @Override
   public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_NEXT) {
     System.out.println("下一步");
                                        return true;
    }
    return false;
   }
  });

你可能感兴趣的:(android,layout,输入法,action,login)