当前位置: 移动技术网 > IT编程>移动开发>Android > Android中系统默认输入法设置的方法(输入法的显示和隐藏)

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

服装数码印花机,青岛正大集团,危狱惊情下载

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,否则会失效

 <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();

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网