Alterdialog中不弹出软键盘原因分析及解决办法
2017-08-23 10:50
465 查看
相信很多人都做过自定义的alterdialog,但不知道有没有发现当alterdialog布局中有exittext的时候即使edittext获得焦点也不能弹出软键盘,是不是很操蛋,而将alterdialog换成dialog的时候就可以的弹出了。下面就去分析一下为什么会这样
看一下alterdialog这个类,点击去就会看到头部注释上有这么一段话
什么意思呢,大概的意思就是当alterdialog检测到布局中有view调用onCheckIsTextEditor返回true的时候会自动给窗口设置上WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM这个flag,那么onCheckIsTextEditor是什么意思?看下解释
啥意思呢,大概也就是说检测是否是文本编辑框,若是的话就返回true,好了那么就知道了当我们的alterdialog布局中有文本编辑框的时候会自动给窗口设置上WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM,那么问题来了这个flag是什么意思,还是看解释吧
意思好像大概也许差不多就是设置了这个flag就不能在弹出软键盘
那知道了原因怎么解决呢,当然就是把这个flag移除就好了,
如果你还想弹出dialog的时候自动弹出软键盘那再加上
好了就这样吧,搬砖去了
看一下alterdialog这个类,点击去就会看到头部注释上有这么一段话
The AlertDialog class takes care of automatically setting * {@link android.view.WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM * android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM} for you based on whether * any views in the dialog return true from {@link View#onCheckIsTextEditor() * View.onCheckIsTextEditor()}. Generally you want this set for a Dialog * without text editors, so that it will be placed on top of the current * input method UI. You can modify this behavior by forcing the flag to your * desired mode after calling {@link #onCreate}.
什么意思呢,大概的意思就是当alterdialog检测到布局中有view调用onCheckIsTextEditor返回true的时候会自动给窗口设置上WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM这个flag,那么onCheckIsTextEditor是什么意思?看下解释
Check whether the called view is a text editor, in which case it * would make sense to automatically display a soft input window for * it. Subclasses should override this if they implement * {@link #onCreateInputConnection(EditorInfo)} to return true if * a call on that method would return a non-null InputConnection, and * they are really a first-class editor that the user would normally * start typing on when the go into a window containing your view.
啥意思呢,大概也就是说检测是否是文本编辑框,若是的话就返回true,好了那么就知道了当我们的alterdialog布局中有文本编辑框的时候会自动给窗口设置上WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM,那么问题来了这个flag是什么意思,还是看解释吧
Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with * respect to how this window interacts with the current method. That * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the * window will behave as if it needs to interact with the input method * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is * not set and this flag is set, then the window will behave as if it * doesn't need to interact with the input method and can be placed * to use more space and cover the input method.
意思好像大概也许差不多就是设置了这个flag就不能在弹出软键盘
那知道了原因怎么解决呢,当然就是把这个flag移除就好了,
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
如果你还想弹出dialog的时候自动弹出软键盘那再加上
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
好了就这样吧,搬砖去了
相关文章推荐
- 白苹果问题解决办法以及原因简单分析
- 数据库连接失败的原因分析及解决办法
- -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.【创建键盘监听事件,然后操作键盘(弹出、收回),结果在运行程序时出现如下错误(如有知道解决办法的朋友请留言探讨!)】
- Java Web开发中,自定义过滤器被执行两次的原因分析及解决办法
- 后端接收不到AngularJs中$http.post发送的数据原因分析及解决办法
- bootstrop 日期控件 datepicker被弹出框dialog覆盖的解决办法
- AMD显卡矿机算力降低原因分析及解决办法
- JavaScript中的ParseInt("08")和“09”返回0的原因分析及解决办法
- [Phonegap+Sencha Touch] 移动开发68 Sencha Touch弹出键盘挡住输入框的解决办法
- 安卓EditText有时点击后无法自动弹出键盘的解决办法;TextWatcher多次调用问题
- HBASE在启动后,Hmaster进程火速关闭的原因简单分析及简易解决办法
- dpdk配置 万兆网卡 驱动 失败的 原因分析及 解决办法
- asp.net 2.0中 FreeTextBox报错的原因分析和解决办法
- SDWebImage与UIScrollView或UICollectionView一起使用多次收到“Received memory warning.”,最终程序闪退的原因分析和解决办法。
- 【android】从源码上分析ListView/GridView调用setEmptyView不起作用的原因及解决办法
- Andorid5.0 bind service 异常和fail原因分析及解决办法
- Session丢失可能的原因分析以及相应的解决办法
- Jquery Ajax请求文件下载操作失败的原因分析及解决办法
- Oracle:ORA-01789: 查询块具有不正确的结果列数 分析原因和解决办法