`
byebyegov5qq
  • 浏览: 1212369 次
文章分类
社区版块
存档分类
最新评论

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);
}


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


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


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics