您的位置:首页 > 运维架构

PopupWindow中EditText被touc时弹出键盘异常解决办法

2012-05-29 12:11 134 查看
今天继续做浮框效果,发现当PopupWindow当中包含EditText时,popupWindow出现后,editText自动猎取焦点,但是软键盘却不能跟着出现。

同样的问题: http://stackoverflow.com/questions/3915230/how-to-show-keyboard-on-popupwindow

http://stackoverflow.com/questions/4593610/android-popupwindow-window-focus-selection/8500786#8500786

原因终于找到了,在我的代码中:

PopupWindow mPopupWindow = new PopupWindow(poupView, 300,300); 我用的是两个参数的构造函数。

查看PopupWindow.java的源代码后发现:

/**

     * <p>Create a new non focusable popup window which can display the

     * <tt>contentView</tt>. The dimension of the window must be passed to

     * this constructor.</p>

     *

     * <p>The popup does not provide any background. This should be handled

     * by the content view.</p>

     *

     * @param contentView the popup's content

     * @param width the popup's width

     * @param height the popup's height

     */

    public PopupWindow(View contentView, int width, int height) {

        this(contentView, width, height, false);

    }

    /**

     * <p>Create a new popup window which can display the <tt>contentView</tt>.

     * The dimension of the window must be passed to this constructor.</p>

     *

     * <p>The popup does not provide any background. This should be handled

     * by the content view.</p>

     *

     * @param contentView the popup's content

     * @param width the popup's width

     * @param height the popup's height

     * @param focusable true if the popup can be focused, false otherwise

     */

    public PopupWindow(View contentView, int width, int height, boolean focusable) {

        if (contentView != null) {

            mContext = contentView.getContext();

            mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);

        }

        setContentView(contentView);

        setWidth(width);

        setHeight(height);

        setFocusable(focusable);

    }

所以就明白,为什么软键盘会不出现了? 

解决方法,换一个构造函数,哈哈。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  service null
相关文章推荐