[英]Android keeps the soft keyboard showing when enter done button
我正在開發一個Android應用程序,需要用戶輸入密碼。 當用戶按下完成或輸入按鈕時,軟鍵盤將消失。 當密碼錯誤並且我希望軟鍵盤仍在屏幕上而不晃動時。 因為我現在的解決方案是讓它消失並再次顯示在屏幕上,所以會發生鍵盤震動,我認為這是不好的設計。 因此,問題是,即使用戶按下Enter鍵,如何始終保持屏幕上始終顯示軟鍵盤?
您的密碼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;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.