<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"
网友评论