要实现的效果如上图所示。注意在右下角出现了一个"搜索"的按钮。
1.首先为布局文件中的Editetext控件中添加 android:imeOptions="actionSearch" 属性。
2.在代码中监听搜索按钮。
mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // TODO Auto-generated method stub if(actionId == EditorInfo.IME_ACTION_SEARCH){ search(); return true; } return false; } });