Edittext 回车键
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@mipmap/bg_login"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/layout_1" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" android:layout_width="283dp" android:layout_height="247dp" android:background="@mipmap/bg1_login" app:layout_constraintVertical_bias="0.45"> <LinearLayout android:id="@+id/layout_name" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginLeft="26dp" android:layout_marginTop="80dp" android:layout_width="228dp" android:layout_height="wrap_content" android:gravity="center_vertical" android:background="@drawable/login_background_name"> <ImageView android:layout_width="17dp" android:layout_height="17dp" android:layout_marginLeft="3dp" android:src="@mipmap/login_icon_phone"/> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@null" android:textSize="10dp" android:imeOptions="actionNext" android:singleLine="true" android:layout_gravity="center_vertical" android:hint="请输入手机号"/> </LinearLayout> <LinearLayout android:id="@+id/layout_pass" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginLeft="26dp" android:layout_marginTop="119dp" android:layout_width="228dp" android:layout_height="wrap_content" android:gravity="center_vertical" android:background="@drawable/login_background_name"> <ImageView android:layout_width="17dp" android:layout_height="17dp" android:layout_marginLeft="3dp" android:src="@mipmap/login_icon_pass"/> <EditText android:id="@+id/password" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="@null" android:textSize="10dp" android:imeOptions="actionDone" android:singleLine="true" android:hint="请输入验证码" /> <TextView android:id="@+id/login_tv_code" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical|right" android:layout_marginRight="5dp" android:textColor="#01CC5A" android:textSize="10dp" android:background="@null" android:text="获取验证码"/> </LinearLayout> <Button android:id="@+id/login" android:layout_width="228dp" android:layout_height="29dp" android:layout_marginTop="193dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" android:textColor="@color/white" android:text="登 录" android:background="@drawable/round_corner_blue_button"/> </androidx.constraintlayout.widget.ConstraintLayout> <LinearLayout android:paddingLeft="7dp" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@+id/layout_1" app:layout_constraintLeft_toLeftOf="@+id/layout_1" android:gravity="center" android:orientation="horizontal"> <CheckBox android:id="@+id/verify_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#ffc6c6c6" android:drawablePadding="1dp" android:text="登录即代表您同意智学汇" android:textSize="9dp" android:drawableLeft="@drawable/login_checkbox_selector" android:button="@null"/> <TextView android:id="@+id/checkbox_tv" android:layout_marginLeft="4dp" app:layout_constraintTop_toTopOf="@+id/verify_checkbox" app:layout_constraintBottom_toBottomOf="@+id/verify_checkbox" app:layout_constraintLeft_toRightOf="@+id/verify_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textColor="#ffc6c6c6" android:textSize="9dp" android:visibility="gone" /> <TextView android:id="@+id/fuwu_tv" app:layout_constraintTop_toTopOf="@+id/verify_checkbox" app:layout_constraintBottom_toBottomOf="@+id/verify_checkbox" app:layout_constraintLeft_toRightOf="@+id/checkbox_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="《服务协议》" android:textColor="#FF4F1D" android:textSize="9dp" /> <TextView android:id="@+id/addtv" app:layout_constraintTop_toTopOf="@+id/verify_checkbox" app:layout_constraintBottom_toBottomOf="@+id/verify_checkbox" app:layout_constraintLeft_toRightOf="@+id/fuwu_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="和" android:textColor="#ffc6c6c6" android:textSize="9dp" /> <TextView android:id="@+id/yinse" app:layout_constraintTop_toTopOf="@+id/verify_checkbox" app:layout_constraintBottom_toBottomOf="@+id/verify_checkbox" app:layout_constraintLeft_toRightOf="@+id/addtv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="《隐私条款》" android:textColor="#FF4F1D" android:textSize="9dp" /> </LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
页面效果:
java代码:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { Log.i("---","搜索操作执行"); } return false; } });