簡介:項(xiàng)目中需要使用鍵盤去監(jiān)聽搜索的事件
第一步:
EditText添加兩個屬性:
android:imeOptions="actionSearch"
android:singleLine="true"
第二步:添加監(jiān)聽 edit.setOnEditorActionListener
edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
? ? public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
searchData();
? ? ? ? }
return false;
? ? }
});