http://m.blog.csdn.net/article/details?id=51350501
以上博文講解很詳細。
如圖所示,有時候為了布局美觀,在搜索時沒有搜索按鈕,而是調用軟件盤上的按鈕。調用的實現只需要在XML在輸入框中加入Android:imeOptions="actionSearch",另外,還要設置android:singleLine="true",保證點擊不會換行,最后調用軟鍵盤時,回車鍵就會顯示搜索二字。
然后調用 OnEditorActionListener,不是OnKeyListener
|
- et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_SEARCH){
- isSearch = true;
- page = 1;
- MyUtils.hideSoftKeyboard(EnterShopActivity.this,v);
- getData();
- return true;
- }
- return false;
- }
- });
|