背景
开发直播需求时,要求直播间内键盘弹起不压缩界面,也就是不能用windowSoftInputMode#adjustResize这个属性,因为他会压缩界面。要不压缩界面肯定就要用adjustNothing,也就是在这个模式下获取键盘弹起高度,下面就是具体实现。
效果图
Record_2021-03-08-13-54-49_8b18727de96c12142f9e23842beba4f0.gif
代码实现
/**
* 获取键盘高度帮助类
*
* @author Liuzj
* @date 2021/3/5
*/
class KeyboardHeightProvider(
activity: FragmentActivity,
parentView: View,
listener: KeyboardHeightListener?,
ignoreStatusBarHeight: Boolean = false
) : PopupWindow(activity) {
interface KeyboardHeightListener {
fun onKeyboardHeightChanged(
keyboardHeight: Int,
keyboardOpen: Boolean,
isLandscape: Boolean
)
}
init {