【问题标题】:Done is not working in softKeyboard in Autocomplete TextView in android完成在 android 的 Autocompletetextview 中的软键盘中不起作用
【发布时间】:2011-03-07 18:35:39
【问题描述】:

我有一个 AutocompleTextView,我想让虚拟键盘在他在 AutocompleTextView 上点击“完成”时消失。到目前为止,按钮“NEXT”/“DONE”什么也没做。有什么想法吗?

【问题讨论】:

  • 你能贴出声明 AutoCompleteTextView 的代码/xml吗?

标签: android


【解决方案1】:

检查android:imeOptions 属性。

【讨论】:

    【解决方案2】:

    将此属性添加到xml 中的AutoCompleteTextView:

    android:imeOptions="actionDone"
    

    【讨论】:

      【解决方案3】:

      只需在您的 XML 布局文件中添加以下内容:

        android:imeOptions="actionDone"
        android:singleLine="true"
      

      【讨论】:

      • 我认为这可能是 Android 中的一个错误,与向后兼容性甚至可能是特定于设备有关。 IME 选项在没有单行(已弃用)的情况下将无法工作,即使指定了 max-lines。
      • 如果我们要启用多行怎么办?
      • 默认情况下 autocompletetextview 单行属性保持为假,这就是为什么当只是把 android:imeOptions="actionDone" 软键盘不起作用
      【解决方案4】:

      以下适用于所有支持 imeOptions 的视图;比如EditText、TextView、AutocompleteTextView等

      在你的 xml 中:

      <autocompleteTextView
      
      inputType = "text"
      imeOptions = "actionDone"
      />
      

      在 Java 中:

      autocomplete = (AutoCompleteTextView) issueDetailView.findViewById(R.id.yourId);
      autocomplete.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                  @Override
                  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                     if(actionId== EditorInfo.IME_ACTION_DONE) {
                        //do Whatever you Want to do
                     }
                      return true;
                  }
              });
      

      【讨论】:

      • 这个问题是我不能让它有超过一行的文本,android:minLines 和 android:lines 都不适用于我的解决方案。
      【解决方案5】:

      在我的情况下,android:imeOptions 仅在我设置 android:inputType 时才有效

      android:inputType="textAutoComplete" android:imeOptions="actionDone"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-14
        • 1970-01-01
        • 2011-11-26
        • 2011-02-17
        • 1970-01-01
        • 2014-09-06
        • 2011-07-28
        相关资源
        最近更新 更多