Android开发之软键盘回车搜索

SouthWind0 2014-11-12

  
   实现点击软键盘的回车键执行搜索功能的点击事件的方法,代码如下:

   

search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH
|| (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
//do something
return true;
}
return false;
}
});

 
同时要对layout里的edittext设置android:singleLine="true" 和android:imeOptions="actionSearch" 



相关推荐