我尝试了这里建议的非常受欢迎的答案
尽管这对我没有用,但其他用户似乎也没有用。也许它已经过时,或者我的代码有冲突。
这是我的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"
沿textNoSuggestions
与textVisiblePassword
作为的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返回未指定?
谢谢
去掉
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
从您EditText
那里,它将解决您的问题。
冲突是由于android:digits
设置的。在这种情况下,默认情况下android:inputType
会设置为numeric
忽略您android:inputType="text|textNoSuggestions|textVisiblePassword"
在xml中输入there()的内容,从而使您android:imeOptions="actionSearch"
无关紧要。
希望能帮助到你。