当前页面弹出软键盘时,显示自定义弹窗后,会导致软键盘被收起,代码如下:
@Component @Entry export struct DialogIssue { build() { Column({ space: 20 }) { TextInput() .width('90%'); Button('弹窗显示2秒后关闭').onClick(() => { const dialog = new CustomDialogController({ builder: TestDialogController(), customStyle: true, autoCancel: false, isModal: true, onWillDismiss: () => { } }); dialog.open(); setTimeout(() => { dialog.close(); }, 2000); }); }.width('100%').height('100%'); } } @CustomDialog export struct TestDialogController { controller?: CustomDialogController; build() { Text('测试信息'); } }
问题示意图如下:

期望是显示弹窗时,软键盘不收起,如何实现?
可以通过以下步骤实现弹出弹窗时不自动收起软键盘:
import { inputMethod } from '@kit.IMEKit'; import { BusinessError } from '@kit.BasicServicesKit'; @CustomDialog export struct TestDialogController { controller?: CustomDialogController; build() { Text('测试信息'); } } @Entry @Component struct TextInputTest { private inputController: inputMethod.InputMethodController = inputMethod.getController(); @State codeTxt: string = ''; keyboardStatus: number = 0; async detach() { await this.inputController.detach(); console.info('Succeeded in detaching inputMethod.'); } async aboutToAppear(): Promise<void> { await this.attachAndListener(); } build() { Column({ space: 10 }) { Button('弹窗显示2秒后关闭').onClick(() => { const dialog = new CustomDialogController({ builder: TestDialogController(), customStyle: true, autoCancel: false, isModal: true, onWillDismiss: () => { } }); dialog.open(); setTimeout(() => { dialog.close(); }, 2000); }); TextInput({ text: this.codeTxt, placeholder: '内容' }) .width('90%') .focusable(false) .onClick(async () => { this.inputController.showTextInput((err: BusinessError) => { if (err) { console.error(`Failed to showTextInput: ${err}`); return; } console.info('Succeeded in showing the inputMethod.'); }); }); } .width('100%').height('100%'); } // 绑定和设置监听 async attachAndListener() { // 输入法配置项 let textConfig: inputMethod.TextConfig = { inputAttribute: { textInputType: inputMethod.TextInputType.TEXT, enterKeyType: inputMethod.EnterKeyType.GO } }; // 控件绑定输入法 await this.inputController.attach(false, textConfig); this.attachListener(); } // 订阅输入法回调 attachListener(): void { this.inputController.on('insertText', (text) => { this.codeTxt += text; console.info(`this.inputText, insertText this.inputText= ${this.codeTxt}`); }); // 订阅输入法应用向左删除事件 this.inputController.on('deleteLeft', (length) => { this.codeTxt = this.codeTxt.substring(0, this.codeTxt.length - 1); console.info(`this.inputText, deleteLeft this.inputText= ${this.codeTxt}, length ${length}`); }); // 订阅输入法应用发送输入法软键盘状态事件 this.inputController.on('sendKeyboardStatus', async (keyboardStatus: inputMethod.KeyboardStatus) => { this.keyboardStatus = keyboardStatus; console.info(`IsaKit this.inputText keyboardStatus= ${this.keyboardStatus}`); }); } }