在Android中的AutoCompleteTextiView上

在Android中的AutoCompleteTextiView上

本文介绍了如何获得“完成"通知在Android中的AutoCompleteTextiView上显示和退出键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:尽管我使用设置了活动xml,但我正在为用户使用 AutoCompleteTextView 选项列表 android:imeOptions ="actionDone" 键盘仍然提供返回选项,而不是为键盘提供完成"选项.

My problem: I'm using an AutoCompleteTextView list of options for the user and despite having the activity xml setup with android:imeOptions="actionDone" the keyboard still provides a return option instead presenting the keyboard with the "Done" option.

我尝试过的操作:我搜索了几则帖子,但找不到与此特定问题有关的帖子.因此,我尝试了另一种适用于 EditText 的帖子中发布的以下解决方案,因此可以将此完成"操作应用于同一活动中的多个AutoCompleteTextViews(发布的此处).

What I have tried: I searched a few posts but could not find one with this specific issue. So I tried the following solution posted from another post applicable for EditText, so I could apply this "Done" action to multiple AutoCompleteTextViews within the same activity (posted here).

同样,问题是尽管为 actionDone 设置了XML AutoCompleteTextView 箭头.

Again, the issue is that despite the XML AutoCompleteTextView is setup for actionDone the keyboard shows the return arrow.

XML

 <AutoCompleteTextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:id="@+id/viewSource"
                    android:hint="@string/hint_source"
                    android:imeOptions="actionDone"
                    android:padding="5dp"
                    android:background="@color/colorWhite"
                    app:layout_constraintStart_toEndOf="@id/lblViewSource"
                    android:layout_marginStart="5dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    android:textSize="12sp"
                    android:layout_marginEnd="5dp"
                    app:layout_constraintBaseline_toBaselineOf="@+id/lblViewSource"/>

AutoCompleteTextView调用代码

sourceTitle.setOnEditorActionListener(new DoneOnEditorActionListener());

用于管理完成"和键盘关闭的自定义类代码

class DoneOnEditorActionListener implements AutoCompleteTextView.OnEditorActionListener {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            return true;
        }
        return false;
    }
}

推荐答案

以下内容最终解决了我的问题.在活动XML中添加并定义 inputType 后,将显示完成按钮.因此,似乎需要使用 imeOptions 定义的 inputType ,否则将不会显示完成按钮.这是来自以下链接的建议之一,尽管未批准任何答案.

The following ended up solving my problem. Once I added and defined the inputType in the activity XML the done button appeared. So, it appears that the inputType needs defined with the imeOptions or the done button will not appear. This was one of the suggestions from the following link though none of answers were approved.

Done在以下位置的softKeyboard中不起作用在Android中自动完成TextView

android:inputType="text"
android:imeOptions="actionDone"

这篇关于如何获得“完成"通知在Android中的AutoCompleteTextiView上显示和退出键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:37