PopupWindow当中包含EditText时,editText获得焦点后软键盘不出现

今天继续做浮框效果,发现当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);
}


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


解决方法,换一个构造函数,哈哈。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值