欢迎使用CSDN-markdown编辑器

来源:互联网 发布:argentum银霜 知乎 编辑:程序博客网 时间:2024/06/18 15:43

android dialog 升起时,保持后台输入法仍然打开

这里有两个重要的参数,现拷贝如下:
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IMWindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
这两个参数相互作用能够应对dialog升起时,后台输入法的状态。

现有两个dialog,第一个dialog先弹出,上面有个EditText,第二个dialog后弹出,上面不可以输入内容,如何保持第二个dialog弹出时,第一个dialog上的输入法不消失呢?就是上面用到的两个参数。(如何判断一个dialog上有没有可编辑的输入框,AlertDialog会遍历View,并使用View的onCheckIsTextEditor()方法来检查有没有可编辑内容)

  1. FLAG_ALT_FOCUSABLE_IM没有设置,FLAG_NOT_FOCUSABLE没有设置
    不做讨论

  2. FLAG_ALT_FOCUSABLE_IM设置,FLAG_NOT_FOCUSABLE没有设置
    键盘会在底部,弹框能够覆盖在输入法上面,且能接受反馈键指令,按返回键第二个弹框消失。

  3. FLAG_ALT_FOCUSABLE_IM没有设置,FLAG_NOT_FOCUSABLE设置
    键盘会在底部,弹框能够覆盖在输入法上面,但是不能接受Button指令,按返回键,底部的键盘消失和第一个dialog消失,第二个dialog还在。

  4. FLAG_ALT_FOCUSABLE_IM设置,FLAG_NOT_FOCUSABLE设置
    键盘会在第二个dialog上面,弹框不能够覆盖在输入法上面,也不能接受Button指令,按返回键,底部的键盘消失,第一个dialog消失,第二个dialog还在。

   /** 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.         */        public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
    /** Window flag: this window won't ever get key input focus, so the         * user can not send key or other button events to it.  Those will         * instead go to whatever focusable window is behind it.  This flag         * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that         * is explicitly set.         *         * <p>Setting this flag also implies that the window will not need to         * interact with         * a soft input method, so it will be Z-ordered and positioned         * independently of any active input method (typically this means it         * gets Z-ordered on top of the input method, so it can use the full         * screen for its content and cover the input method if needed.  You         * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */        public static final int FLAG_NOT_FOCUSABLE      = 0x00000008;
0 0