android设置软键盘搜索键以及监听搜索键点击事件

来源:互联网 发布:simnow python 编辑:程序博客网 时间:2024/06/11 10:25

这里写图片描述

如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮。调用的实现只需要在XML在输入框中加入   android:imeOptions="actionSearch",另外,还要设置android:singleLine="true",保证点击不会换行,最后调用软键盘时,回车键就会显示搜索二字。然后调用 OnEditorActionListener,不是OnKeyListeneret_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;      }  });  在androidMainfest.xml文件中在此Activity中写入android:windowSoftInputMode="adjustPan"  可以防止软键盘会把原来的界面挤上去的问题
0 0
原创粉丝点击