源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android中系统默认输入法设置的方法(输入法的显示和隐藏)

  • 时间:2020-04-04 02:02 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android中系统默认输入法设置的方法(输入法的显示和隐藏)
[b]1.调用显示系统默认的输入法[/b] [b]方法一、[/b]
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(m_receiverView(接受软键盘输入的视图(View)),InputMethodManager.SHOW_FORCED(提供当前操作的标记,SHOW_FORCED表示强制显示)); [b]方法二、[/b]
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); (这个方法可以实现输入法在窗口上切换显示,如果输入法在窗口上已经显示,则隐藏,如果隐藏,则显示输入法到窗口上)
[b]2.调用隐藏系统默认的输入法[/b]
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); (WidgetSearchActivity是当前的Activity)
[b]3.获取输入法打开的状态[/b]
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
isOpen若返回true,则表示输入法打开
[b]1、//隐藏软键盘 [/b]
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
[b]2、//显示软键盘,控件ID可以是EditText,TextView [/b]
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID, 0); 
[b]3、不自动弹出键盘:[/b] 带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法: [b]方法一:[/b]在mainfest文件中把对应的activity设置 android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"。 [b]方法二:[/b]可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。 注意TextView不要设置Visiable=gone,否则会失效 ,可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus。 注意TextView不要设置Visiable=gone,否则会失效
 <TextView
     android:id="@+id/text_notuse"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:focusable="true"
 android:focusableInTouchMode="true" />
 TextView textView = (TextView)findViewById(R.id.text_notuse);
 textView.requestFocus();
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部