android显示和隐藏软键盘
显示键盘: EditText editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); InputMethodManager inputManager = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(editText, 0); 首先要对指定的输入框请求焦点。然后调用输入管理器弹出软键盘。 警告:对于刚跳到一个新的界面就要弹出软键盘的情况上述代码可能由于界面为加载完全而无法弹出软键盘。此时应该适当的延迟弹出软键盘如998毫秒(保证界面的数据加载完成)。实例 [代码]java代码: Timer timer = new Timer(); timer.schedule(new TimerTask(){ public void run(){ InputMethodManager inputManager = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(editText, 0); } }, 998); 隐藏键盘: 方法二: 让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);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。