我正在开发一个Android应用程序,需要用户输入密码。当用户按下done或enter按钮时,软键盘将消失。当密码错误时,我希望软键盘仍然在屏幕上不抖动。因为我现在的解决方案是让它消失,并将它重新显示在屏幕上,键盘会发生抖动,我认为这是一个糟糕的设计。因此,问题是,即使用户按下enter按钮,我如何使软键盘始终显示在屏幕上?
发布于 2016-12-05 13:41:51
您的密码edittext如下所示
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textPassword" />用于检查密码的java代码。示例:密码id 12345
EditText editText = (EditText) findViewById(R.id.editText);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
if (v.getText().toString().equals("12345")) {
// if the pass word is 12345
// hide your keyboard code
Log.e("!_@@ ", "true");
} else {
// if password is not 12345
// not hide keyboard code
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Log.e("!_@@ ", "false");
}
handled = true;
}
return handled;
}
});https://stackoverflow.com/questions/40966220
复制相似问题