简介:项目中需要使用键盘去监听搜索的事件
第一步:
EditText添加两个属性:
android:imeOptions="actionSearch"
android:singleLine="true"
第二步:添加监听 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;
}
});