Android 失去焦点,关闭弹出的软键盘

来源:互联网 发布:lua 5.1 windows 编辑:程序博客网 时间:2024/05/29 07:09

如何设置进入Activity不弹出输入法


方法一:在AndroidMainfest.xml中选择该Activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden,代码如下:
<!--进入Activity窗口默认不打开软键盘--><activity android:name=".view.Activity" android:windowSoftInputMode="adjustUnspecified|stateHidden"/>

方法二:让EditText失去焦点,使用EditText的clearFocus方法,代码如下:
EditText edit=(EditText)findViewById(R.id.edit);   edit.clearFocus();

方法三:强制隐藏Android输入法窗口,代码如下:
EditText edit=(EditText)findViewById(R.id.edit);    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);   imm.hideSoftInputFromWindow(edit.getWindowToken(),0); 

方法四:EditText始终不弹出软键盘,代码如下:
EditText edit=(EditText)findViewById(R.id.edit);   edit.setInputType(InputType.TYPE_NULL);   

如何设置点击屏幕空白处,使得EditText失去焦点,并关闭软键盘

// 定义,并设置监听器       private LinearLayout loginpage;    loginpage = (LinearLayout) findViewById(R.id.loginpage);    loginpage.setOnTouchListener(this);// 获取焦点loginpage.setFocusable(true);loginpage.setFocusableInTouchMode(true);loginpage.requestFocus();// 关闭输入法InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(loginpage.getWindowToken(), 0);



















0 0
原创粉丝点击