温馨提示:本文翻译自stackoverflow.com,查看原文请点击:android - Trying to make the soft keyboard enter button say search or display search magnifying glass and hand
android xml

android - 想使软键盘的“输入”按钮说出搜索或显示搜索放大镜和手

发布于 2020-03-30 21:51:42

我尝试了这里建议的非常受欢迎的答案

尽管这对我没有用,但其他用户似乎也没有用。也许它已经过时,或者我的代码有冲突。

这是我的xml EditText

<EditText
        android:id="@+id/editText_letter_entry"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:background="@drawable/edit_text_rounded"
        android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
        android:drawableEnd="@drawable/ic_search_black_24dp"
        android:hint="@string/enter_letters"
        android:importantForAutofill="no"
        android:inputType="text|textNoSuggestions|textVisiblePassword"
        android:maxLength="15"
        android:maxLines="1"
        android:imeOptions="actionSearch"
        android:paddingLeft="@dimen/et_padding_left_right"
        android:paddingRight="@dimen/et_padding_left_right"
        app:layout_constraintBottom_toTopOf="@+id/bottomBannerAdView"
        app:layout_constraintEnd_toStartOf="@+id/guideline2Container"
        app:layout_constraintStart_toStartOf="@+id/guideline1Container"
        app:layout_constraintTop_toTopOf="parent" />

正如你可以看到我有android:imeOptions="search" & android:inputType="text"沿textNoSuggestionstextVisiblePassword作为的inputType。我有只尝试此text作为inputType类似建议的其他答案,但这个并没有什么差别,我不想在键盘上的任何建议。

至于这个侦听器,尽管有点麻烦,但我设法使它正常工作,因为action id回来了IME_ACTION_UNSPECIFIED,所以我只是处理了这个。可以在这里看到:

 et_letter_entry.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED ) {
                preformSearch();
                return true;
            }
            return false;
        }
    });

我目前有一个用于换行的图标,而不是search一个搜索图标。

android:imeOptions="search"在我的情况下,为什么XML似乎没有受到影响

为什么输入按钮显示换行图标?

为什么操作ID返回未指定?

谢谢

查看更多

提问者
COYG
被浏览
100
Paul Ost 2020-01-31 19:07

去掉

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"

从您EditText那里,它将解决您的问题。

冲突是由于android:digits设置的。在这种情况下,默认情况下android:inputType会设置为numeric忽略您android:inputType="text|textNoSuggestions|textVisiblePassword"在xml中输入there()的内容,从而使您android:imeOptions="actionSearch"无关紧要。

希望能帮助到你。