美文网首页
EditText 设置键盘回车为搜索

EditText 设置键盘回车为搜索

作者: Lost_Robot | 来源:发表于2020-03-31 21:21 被阅读0次
<EditText
            android:id="@+id/faq_search_et"
            android:layout_width="100dp"
            android:layout_height="45dp"
            android:imeOptions="actionSearch"
            android:hint="@string/search_hint"
            android:maxLines="1"
            android:singleLine="true"
    />


faq_search_et.setOnEditorActionListener { v, actionId, event ->

            if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                hideKeyBoard(faq_search_et);
                initSearch()
                return@setOnEditorActionListener true
            } else {
                return@setOnEditorActionListener false
            }
        }


设置EditText的回车实现搜索功能:

 android:imeOptions="actionSearch"
 android:maxLines="1"

或者:

faq_search_et.imeOptions = EditorInfo.IME_ACTION_SEARCH

如果需要同时将回车显示为"搜索":

android:singleLine="true"

相关文章

网友评论

      本文标题:EditText 设置键盘回车为搜索

      本文链接:https://www.haomeiwen.com/subject/ocoguhtx.html