【问题标题】:Android keeps the soft keyboard showing when enter done buttonAndroid在输入完成按钮时保持软键盘显示
【发布时间】:2017-04-19 08:55:30
【问题描述】:

我正在开发一个 Android 应用程序,需要用户输入密码。当用户按下完成或进入按钮时,软键盘将消失。 当密码错误并且我希望软键盘仍然在屏幕上而不晃动时。因为我现在的解决方案是让它消失并再次出现在屏幕上,所以会发生键盘抖动,我认为这是糟糕的设计。 所以问题是我怎样才能让软键盘一直显示在屏幕上,即使用户按下回车键?

【问题讨论】:

    标签: android soft-keyboard


    【解决方案1】:

    你的密码编辑文本像这样

     <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;
                        }
                    });
    

    【讨论】:

    • 我已经写了类似你的解决方案的代码,但我认为它没有解决我的问题,我的问题是当密码不是 12345 时如何保持软键盘显示。
    猜你喜欢
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多