美文网首页
关于自定义的dialog中的EditText自动弹出软键盘

关于自定义的dialog中的EditText自动弹出软键盘

作者: Li李萌 | 来源:发表于2017-09-29 02:31 被阅读0次

我在网上用了很多方法都没有成功,但是不能弹出软件不过我找到了两个方法是可以实现的.

第一种方法:

//只用下面这一行弹出对话框时需要点击输入框才能弹出软键盘

alert_leaveMsg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

//加上下面这一行弹出对话框时软键盘随之弹出??

alert_leaveMsg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

方法二:

/**

* EditText获取焦点并显示软键盘

*/

public  void showSoftInputFromWindow( EditText editText) {

editText.setFocusable(true);

editText.setFocusableInTouchMode(true);

editText.requestFocus();

//getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

//调用系统输入法

InputMethodManager inputManager = (InputMethodManager) editText

.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

inputManager.showSoftInput(editText, 0);

}

第三种方法:

是在style中设置dialog样式

通过style设置软键盘e:

相关文章

网友评论

      本文标题:关于自定义的dialog中的EditText自动弹出软键盘

      本文链接:https://www.haomeiwen.com/subject/rcrjdxtx.html