EditText设置输入法隐藏

来源:互联网 发布:iphone屏幕测试软件 编辑:程序博客网 时间:2024/05/16 05:45

在onCreate方法中设置

//进入activity中不主动弹出输入法,点击EditText时弹出输入法.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

判断输入法打开则关闭:

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);  

            //判断输入法是否打开
        boolean isOpen=imm.isActive();  
         if (isOpen) {

                            //隐藏输入法
                imm.hideSoftInputFromWindow(textactivity.this.getCurrentFocus().getWindowToken(),  InputMethodManager.HIDE_NOT_ALWAYS);
           }


如果输入法打开则关闭,如果没打开则打开

    InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

          //设置输入法开关(toggle)

        m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); 

0 0
原创粉丝点击