调用和隐藏系统输入法
2016-01-25 10:43
357 查看
1.调用显示系统默认的输入法
方法一、
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));
方法二、
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (这个方法可以实现输入法在窗口上切换显示,如果输入法在窗口上已经显示,则隐藏,如果隐藏,则显示输入法到窗口上)
2.调用隐藏系统默认的输入法
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)
3.获取输入法打开的状态
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
isOpen若返回true,则表示输入法打开
1、//隐藏软键盘
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
2、//显示软键盘,控件ID可以是EditText,TextView
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID, 0);
3、不自动弹出键盘:
带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法:
方法一:在mainfest文件中把对应的activity设置
android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。
方法二:可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。
注意TextView不要设置Visiable=gone,否则会失效
,可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。
注意TextView不要设置Visiable=gone,否则会失效
方法一、
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示));
方法二、
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (这个方法可以实现输入法在窗口上切换显示,如果输入法在窗口上已经显示,则隐藏,如果隐藏,则显示输入法到窗口上)
2.调用隐藏系统默认的输入法
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)
3.获取输入法打开的状态
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
isOpen若返回true,则表示输入法打开
1、//隐藏软键盘
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
2、//显示软键盘,控件ID可以是EditText,TextView
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID, 0);
3、不自动弹出键盘:
带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法:
方法一:在mainfest文件中把对应的activity设置
android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。
方法二:可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。
注意TextView不要设置Visiable=gone,否则会失效
,可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。
注意TextView不要设置Visiable=gone,否则会失效
1 <TextView 2 android:id="@+id/text_notuse" 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content" 5 android:focusable="true" 6 android:focusableInTouchMode="true" /> 7 8 TextView textView = (TextView)findViewById(R.id.text_notuse); 9 textView.requestFocus();
相关文章推荐
- iOS UICollectionView之-(水平滚动)
- linux下移动或者复制文件覆盖相同文件夹时,文件夹里面的每个文件都提示是否覆盖
- HashTable浅析
- proxy_redirect参数的作用
- Error:Execution failed for task ':app:processDevDebugResources'. > com.android.ide.common.process.Pr
- 初学WCF--最基础知识(1)
- 变量
- Gradle 导入开源工程 常见问题解决方法
- 2016年我的读书计划
- Entity Framework数据库初始化四种策略
- Leetcode: Longest Increasing Path in a Matrix
- 安装或者更换cocoapods版本出现的问题
- 关于python-NameError: global name 'platform' is not defined
- Linux Source命令及脚本的执行方式解析
- PDF文件中的数字签名之(在一个PDF文件的签名代表)
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
- Lua学习笔记-table中的混合风格&多项式求和
- Virtual Initialization - 虚初始化
- Android开发之获取状态栏高度、屏幕的宽和高
- Spark MLlib实现的广告点击预测–Gradient-Boosted Trees