PopupWindow与软件盘冲突,且软键盘出现背景色
最近写了一个项目,在项目中运用了popwindow,该popwindow中有个editText,原以为editText可以直接弹出软件盘,谁知道焦点冲突了
解决方案:为了让软件盘可以弹出,那么可以让popwindow获得焦点,这样当popwindow弹出时不会出现软件盘,触发editText,既可以出现软件盘,代码如下:
public void initDate(){
if (contentView==null){
contentView = View.inflate(mContext, R.layout.pop_search, null);
}
if (mPopupWindow==null){
mPopupWindow=new PopupWindow(contentView,
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
//设置可以获取焦点,否则弹出菜单中的EditText是无法获取输入的
mPopupWindow.setFocusable(true);
//这句是为了设置软件弹出不回出现底层背景颜色
mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
mPopupWindow.setOnDismissListener(this);
}
mPopupWindow.showAtLocation(view,Gravity.BOTTOM |Gravity.LEFT,0,0);
et_search = contentView.findViewById(R.id.et_search);
mRecyclerView

在Android项目中使用PopupWindow时遇到焦点冲突,导致软键盘无法正常弹出。通过让PopupWindow获取焦点并设置相关属性,如setFocusable(true)和setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE),解决了焦点问题。同时,为避免软键盘弹出时底层背景色显示,使用setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)防止背景色露出。
最低0.47元/天 解锁文章
184

被折叠的 条评论
为什么被折叠?



