中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何监听输入法软键盘显示或隐藏事件
微信扫码分享
import { inputMethodEngine } from '@kit.IMEKit'; import { BusinessError } from '@kit.BasicServicesKit'; static onKeyboardListener(callback: (show: boolean) => void) { try { inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { if (callback) { callback(true); //键盘显示 } }); inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { if (callback) { callback(false); //键盘隐藏 } }); } catch (err) { let error = err as BusinessError; console.log(`KeyboardUtil-onKeyboardListener-异常 ~ code: ${error.code} -·- message: ${error.message}`); } }