uni-app 【报Bug】配置 manifest 中 app-plus.softinput.mode 配置为 adjustPan 云端打包后,安卓中 onKeyboardHeightChange 事件失效

uni-app 【报Bug】配置 manifest 中 app-plus.softinput.mode 配置为 adjustPan 云端打包后,安卓中 onKeyboardHeightChange 事件失效

开发环境 版本号 项目创建方式
Mac macOS Big Sur 11.2.3 HBuilderX

示例代码:

<template> <view class="content"> <input class="input" placeholder="测试键盘44431" /> <input class="input" placeholder="测试键盘44431" @keyboardheightchange="showToast(`input.@keyboardheightchange: ${$event.detail.height}` )" /> </view> </template> <script> export default { onLoad() { // 全局键盘高度监听事件 uni.onKeyboardHeightChange(res => this.showToast(`uni.onKeyboardHeightChange: ${res.height}`)) }, methods: { showToast(title) { uni.showToast({ title, icon: 'none', }) }, } } </script> <style> .input { padding: 0 30rpx; height: 100rpx; background: rgba(0, 0, 0, 0.1); margin-bottom: 30rpx; } </style>

更多关于uni-app 【报Bug】配置 manifest 中 app-plus.softinput.mode 配置为 adjustPan 云端打包后,安卓中 onKeyboardHeightChange 事件失效的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

去掉 adjustPan 的配置后,重新云端打包安卓下键盘高度事件监听就恢复了

更多关于uni-app 【报Bug】配置 manifest 中 app-plus.softinput.mode 配置为 adjustPan 云端打包后,安卓中 onKeyboardHeightChange 事件失效的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个已知的 uni-app 平台兼容性问题。当在 manifest.json 中配置 app-plus.softinput.modeadjustPan 时,Android 端的 onKeyboardHeightChange 事件确实会失效。

问题原因: adjustPan 模式会调整页面布局,使输入框不被键盘遮挡。在这种模式下,系统键盘事件的处理机制与 adjustResize 模式不同,导致键盘高度变化事件无法正常触发。

解决方案:

  1. 如果需要监听键盘高度变化,建议将 app-plus.softinput.mode 改为 adjustResize
  2. 或者保持 adjustPan 配置,但通过其他方式处理键盘相关的布局调整

代码调整示例:

// manifest.json
"app-plus": {
  "softinput": {
    "mode": "adjustResize"
  }
}
回到顶部