edittext把软键盘上的回车键改为搜索、发送或者 下一步,窗口随软键盘弹出而改变。

时间:2023-03-08 16:31:45

http://m.blog.****.net/article/details?id=51350501

以上博文讲解很详细。

如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮。调用的实现只需要在XML在输入框中加入Android:imeOptions="actionSearch",另外,还要设置android:singleLine="true",保证点击不会换行,最后调用软键盘时,回车键就会显示搜索二字。

然后调用 OnEditorActionListener,不是OnKeyListener

edittext把软键盘上的回车键改为搜索、发送或者 下一步,窗口随软键盘弹出而改变。
edittext把软键盘上的回车键改为搜索、发送或者 下一步,窗口随软键盘弹出而改变。
  1. et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  2. @Override
  3. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  4. if (actionId == EditorInfo.IME_ACTION_SEARCH){
  5. isSearch = true;
  6. page = 1;
  7. MyUtils.hideSoftKeyboard(EnterShopActivity.this,v);
  8. getData();
  9. return true;
  10. }
  11. return false;
  12. }
  13. });