
如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮。调用的实现只需要在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;
- }
- });
|
在androidMainfest.xml文件中在此Activity中写入:
- android:windowSoftInputMode="adjustPan"
可以防止软键盘会把原来的界面挤上去的问题。
转自:http://blog.csdn.net/jyz_2015/article/details/51543318