有一个UI,上方为Text,Text有bindMenu,点击会弹出Menu;下方为RichEditor,点击会弹出键盘。当RichEditor中处理输入态时、键盘处于弹出状态,点击Text弹出Menu,RichEditor中失焦、键盘消失。Menu消失后,RichEditor又获焦,键盘又弹出,怎样让键盘不再弹出?
问题效果预览:

@Entry @Component struct Index { message: string = 'Operation'; controller: RichEditorController = new RichEditorController(); options: RichEditorOptions = { controller: this.controller }; build() { Column() { Text(this.message) .fontSize($r('app.float.page_text_font_size')) .fontWeight(FontWeight.Bold) .margin({ top: 20, bottom: 20 }) .bindMenu(this.MyMenu) .id('TextComponent') RichEditor(this.options) .height(200) .borderWidth(2) .borderColor(Color.Black) .width('99%') .margin({ top: 20, bottom: 20 }) .enableKeyboardOnFocus(false) .onReady(() => { this.controller.addTextSpan('创建RichEditor组件。', { style: { fontColor: Color.Black, fontSize: 15 } }); }) } .height('100%') .width('100%') } @Builder MyMenu() { Menu() { MenuItem({ content: '复制', labelInfo: 'Ctrl+C' }); MenuItem({ content: '粘贴', labelInfo: 'Ctrl+V' }); } } }
@Entry @Component struct Scene2 { message: string = 'Operation'; @State richEditorClick: boolean = false; controller: RichEditorController = new RichEditorController(); options: RichEditorOptions = { controller: this.controller }; build() { Column() { Text(this.message) .fontSize($r('app.float.page_text_font_size')) .fontWeight(FontWeight.Bold) .margin({top: 20, bottom: 20}) .bindMenu(this.MyMenu) .id('Operation') RichEditor(this.options) .height(200) .borderWidth(2) .borderColor(Color.Black) .width('99%') .margin({top: 20, bottom: 20}) .onFocus(() => { console.info(`RichEditor focus`); if (!this.richEditorClick) { this.getUIContext().getFocusController().clearFocus(); // 部分组件可以使用该方法,如:Button组件支持,Text组件不支持 } }) .onBlur(() => { console.info(`RichEditor blur`); this.richEditorClick = false; }) .onClick(() => { console.info(`RichEditor click`); this.richEditorClick = true; }) .onReady(() => { this.controller.addTextSpan('创建RichEditor组件。', { style: { fontColor: Color.Black, fontSize: 15 } }); }) } .height('100%') .width('100%') } @Builder MyMenu() { Menu() { MenuItem({ content: '复制', labelInfo: 'Ctrl+C' }); MenuItem({ content: '粘贴', labelInfo: 'Ctrl+V' }); } } }
@Entry @Component struct Scene3 { message: string = 'Operation'; controller: RichEditorController = new RichEditorController(); options: RichEditorOptions = { controller: this.controller }; build() { Column() { Button(this.message) .fontSize($r('app.float.page_text_font_size')) .fontWeight(FontWeight.Bold) .margin({top: 20, bottom: 20}) .bindMenu(this.MyMenu) .id('Operation') RichEditor(this.options) .height(200) .borderWidth(2) .borderColor(Color.Black) .width('99%') .margin({top: 20, bottom: 20}) .onReady(() => { this.controller.addTextSpan('创建RichEditor组件。', { style: { fontColor: Color.Black, fontSize: 15 } }); }) } .height('100%') .width('100%') } @Builder MyMenu() { Menu() { MenuItem({ content: '复制', labelInfo: 'Ctrl+C' }) MenuItem({ content: '粘贴', labelInfo: 'Ctrl+V' }) } .onBlur(() => { // 部分组件可以使用该方法,如:Button组件支持,Text组件不支持 this.getUIContext().getFocusController().requestFocus('Operation'); }) } }