Android 软键盘相关

来源:互联网 发布:淘宝怎么参加双11活动 编辑:程序博客网 时间:2024/06/05 18:34

隐藏软键盘

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);//This can be used to suppress the keyboard until the user actually touched the edittext view.(近页面时隐藏软件盘,当获取到焦点时软键盘会弹出)

强制隐藏,不再弹出

InputMethodManager inputMethodManager =        (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);        //或者getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

切换状态

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  //得到InputMethodManager的实例 if (imm.isActive()) { //如果开启 imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); //关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的 } 

强制弹出软键盘

InputMethodManager imm =(InputMethodManager)v.getContext( ).getSystemService(Context.INPUT_METHOD_SERVICE);imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED); // imm.showSoftInput(v,InputMethodManager.SHOW_FORCED); 此方法很像,但是不可行
0 0
原创粉丝点击