遇到的问题
- 软件盘无法弹出
答:设置popwindow的isFocusable为true,popwindow应获取焦点。但是设置为true之后点击其他可以弹出popwindow的按钮,不会直接弹出其他popwindow,而是先取消显示当前popwindow,再次点击才会显示其他popwindow。
filterPopWindow.isFocusable = true
- 软件盘弹出后,有的手机popwindow上移,有些手机popwindow位置高度不变,内容也不上移,导致popwindow部分内容被挡住了。
答:监听软件盘的弹出和关闭,对应的修改popwindow和里面内容布局的高度。
//软键盘弹出和收回的监听
val softKeyboardStateHelper1 =
SoftKeyboardStateHelper(tvFilter)
softKeyboardStateHelper1.addSoftKeyboardStateListener(object : SoftKeyboardStateHelper.SoftKeyboardStateListener {
override fun onSoftKeyboardOpened(keyboardHeightInPx: Int) {
//更新popwindow的高宽
filterPopWindow.update(llFunctionButton, ViewGroup.LayoutParams.MATCH_PARENT,llModuleLoading.height - llFunction.height+if (isFromNavigation) ScreenUtil.dp2px(50f) else 0)
val param= filterPopWindow.llContent.layoutParams
val llContentHight=if (filterPopWindow.llContent.height>filterPopWindow.height) filterPopWindow.height-ScreenUtil.dp2px(20f) else filterPopWindow.llContent.height
param.height=llContentHight
filterPopWindow.llContent.layoutParams=param
val param2= filterPopWindow.maxHeightF.layoutParams
param2.height=llContentHight-filterPopWindow.clBottomFuction.height
filterPopWindow.maxHeightF.layoutParams=param2
val param3= filterPopWindow.llContainer.layoutParams
param3.height=llContentHight-filterPopWindow.clBottomFuction.height
filterPopWindow.llContainer.layoutParams=param3
val param4= filterPopWindow.nestSw.layoutParams
param4.height=llContentHight-filterPopWindow.clBottomFuction.height
filterPopWindow.nestSw.layoutParams=param4
}
override fun onSoftKeyboardClosed() {
filterPopWindow.update(llFunctionButton, ViewGroup.LayoutParams.MATCH_PARENT,llModuleLoading.height - llFunction.height+if (isFromNavigation) ScreenUtil.dp2px(50f) else 0)
val param= filterPopWindow.llContent.layoutParams
param.height=ViewGroup.LayoutParams.WRAP_CONTENT
filterPopWindow.llContent.layoutParams=param
val param2= filterPopWindow.maxHeightF.layoutParams
param2.height=ViewGroup.LayoutParams.WRAP_CONTENT
filterPopWindow.maxHeightF.layoutParams=param2
val param3= filterPopWindow.llContainer.layoutParams
param3.height=ViewGroup.LayoutParams.WRAP_CONTENT
filterPopWindow.llContainer.layoutParams=param3
val param4= filterPopWindow.nestSw.layoutParams
param4.height=ViewGroup.LayoutParams.WRAP_CONTENT
filterPopWindow.nestSw.layoutParams=param4
}
})