【问题标题】:How can i hide/disable done button on soft keyboard android?如何隐藏/禁用软键盘 android 上的完成按钮?
【发布时间】:2019-06-24 22:15:39
【问题描述】:

我正在使用 Amazon S3 api。

问题:使用 TextWatcher。一旦用户在编辑文本中输入超过 3 个字符,就会调用 api 并显示匹配的结果。一旦用户点击软键盘上的完成/输入按钮,问题就会开始,再次调用 api 并再次搜索。我可以以某种方式停止第二次通话吗?谢谢!

【问题讨论】:

  • 需要回车键还是可以去掉?
  • 我建议您以编程方式对 ime 选项进行破解

标签: android textwatcher android-keypad


【解决方案1】:

您可以从 xml 更改它:

<EditText
...
android:imeOptions="actionNone"/>

或来自代码:

editText.setImeOptions(EditorInfo.IME_ACTION_NONE);

每当用户触发软键盘时,它都会删除完成按钮

【讨论】:

    【解决方案2】:

    也许您可以尝试覆盖控件中的 onKeyListener 方法,让它检测按下的键是否为“输入”并添加您希望您的“输入”键执行的代码?

    edittext.setOnKeyListener(new View.OnKeyListener() {

    【讨论】:

      【解决方案3】:

      只需处理完成的点击并隐藏软键盘

      editText = (EditText) findViewById(R.id.edit_text);
      
      editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (actionId == EditorInfo.IME_ACTION_DONE) {
                 // hide your keyboard here
                 try {
                         InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                         if (inputMethodManager != null && activity.getCurrentFocus() != null) {
                   inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
                         }
                 } catch (Exception e) {
                   e.printStackTrace();
                 }
                 return true;
              }
              return false;
          }
      });
      

      【讨论】:

        【解决方案4】:

        添加

        android:maxLines="1"
        

        你的 xml 和输入按钮应该被禁用。

        【讨论】:

          【解决方案5】:

          你可以点赞editText.setImeOptions(EditorInfo.IME_ACTION_NONE);

          但它不会隐藏 Enter/Next

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2011-12-22
            • 1970-01-01
            • 2011-03-21
            • 1970-01-01
            • 2012-02-18
            • 2011-02-03
            • 2014-01-31
            相关资源
            最近更新 更多