[Android]搜索界面--自动弹出键盘,并点击键盘搜索进行搜索
2014-09-05 14:34
477 查看
功能分析:
进入搜索页面,自动弹出键盘,并且可以点击键盘搜索按钮进行搜索,并自动隐藏键盘。
1.在XML在输入框中加入android:imeOptions="actionSearch"
import android.widget.TextView.OnEditorActionListener;)
3.在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan"可以防止软键盘会把原来的界面挤上去的问题,stateVisible负责让键盘自动弹出
进入搜索页面,自动弹出键盘,并且可以点击键盘搜索按钮进行搜索,并自动隐藏键盘。
1.在XML在输入框中加入android:imeOptions="actionSearch"
<EditText android:id="@+id/et_keyword" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_toRightOf="@id/icon_keyword" android:background="@color/transplant" android:hint="请输入关键字" android:imeOptions="actionSearch" android:padding="5dp" android:singleLine="true" android:textColor="@color/white" android:textColorHint="@color/white" />2.自动弹出键盘
et_keyword = (EditText) findViewById(R.id.et_keyword); et_keyword.setSelected(true); et_keyword.requestFocus();//获得焦点3.然后调用 OnEditorActionListener,不是OnKeyListener(
import android.widget.TextView.OnEditorActionListener;)
<span style="font-size:18px;">et_keyword.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { if (arg1 == EditorInfo.IME_ACTION_SEARCH) { //添加搜索事件 hideInput(mContext);//隐藏软键盘 } return false; } });</span>
/** * 隐藏软键盘 */ private static InputMethodManager manager;// 输入法管理器 用户隐藏软键盘 private void hideInput(Context context) { if(manager==null){ manager = ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)); } manager.hideSoftInputFromWindow(((Activity) context) .getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }
3.在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan"可以防止软键盘会把原来的界面挤上去的问题,stateVisible负责让键盘自动弹出
<span style="font-size:18px;">android:windowSoftInputMode="adjustPan|stateVisible"</span>
相关文章推荐
- Android是一个针对触摸屏专门设计的操作系统,当点击编辑框,系统自动为用户弹出软键盘,以便用户进行输入。 那么,弹出软键盘后必然会造成原有布局高度的减少,那么系统应该如何来处理布局的减少
- Android搜索框输入内容点击键盘的搜索按钮进行搜索
- android进入Activity阻止键盘自动弹出
- android防止EditText自动弹出软键盘
- android 仿多米音乐点击弹出歌词界面(部分)
- Android应用实例之---使用Linkify + 正则式区分微博文本链接及跳转处理如同新浪微博Android版的应用上,当我们点击微博文本上的链接会自动跳转界面,或网站链接跳转网页浏览,或邮箱链接
- Android通过事件触发EditText焦点和自动弹出键盘
- [转载]android 软键盘弹出时的界面控制
- android软键盘弹出,会把原来的界面挤上去的问题 处理方法
- android隐藏以及显示软键盘以及不自动弹出键盘的方法
- Android中如何自动弹出软键盘
- 解析android中隐藏与显示软键盘及不自动弹出键盘的实现方法
- android隐藏以及显示软键盘以及不自动弹出键盘的方法
- Android软键盘弹出,界面整体上移的问题【转】
- android自动弹出软键盘
- 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan" 可以让界面不被弹出的键盘挤上去。
- Android 模拟器按Ctrl+F11切换横屏后,点击EditText不弹出软键盘
- Android 平板 控制软键盘只弹出一半,自动盯着界面中EditText,从而让界面可以自由看全的方法:
- android自动弹出软键盘(输入键盘)
- 解析android中隐藏与显示软键盘及不自动弹出键盘的实现方法