问题描述
对于编辑文本,我具有以下定义:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp">
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/loginColorPrimaryDark" />
</android.support.design.widget.TextInputLayout>
在“操作”按钮上,我要启动登录:
edt_password.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(textView.getWindowToken(),
InputMethodManager.RESULT_UNCHANGED_SHOWN);
attemptLogin();
return true;
}
return false;
}
});
在Nexus 5设备上,所有设备均正常运行时,在索尼设备上,我得到以下信息:
因此,无论是android:imeActionLabel="@string/action_sign_in_short"
还是android:imeOptions="actionUnspecified"
都没有得到尊重。
令我惊讶的是,我自己还没有指定,我在Android Studio中创建项目时在项目模板中选择了“登录活动”。 好像坏了!
1楼
尝试使用下面的代码...对我来说,它适用于所有设备。希望对您有所帮助
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="@string/hint_password"
android:imeOptions="actionDone"
android:imeActionLabel="SIGN UP"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/black_color"/>
confirmPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
attemptLogin();
return false;
}
return false;
}
});