openharmony 鸿蒙 js-apis-inputmethodlist

2025-06-12 浏览 (1)

@ohos.inputMethodList (Input Method List)

The inputMethodList module is oriented to system applications and input method applications. It provides APIs for implementing an input method list. This list displays the default input method subtypes and third-party input methods. Users can use this list to switch from the default input method to another input method.

NOTE

The initial APIs of this module are supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { inputMethod } from '@kit.IMEKit';

Child Components

Not supported

Attributes

The universal attributes are not supported.

InputMethodListDialog

InputMethodListDialog({controller: CustomDialogController, patternOptions?: PatternOptions})

Implements a dialog box showing the input method list.

Decorator type: @CustomDialog

System capability: SystemCapability.MiscServices.InputMethodFramework

Parameters

NameTypeMandatoryDecoratorDescription
controllerCustomDialogControllerYes-Controller for the dialog box showing the input method list.
patternOptionsPatternOptionsNo-Input method pattern options (for the default input method only).

PatternOptions

System capability: SystemCapability.MiscServices.InputMethodFramework

NameTypeRead-OnlyOptionalDescription
defaultSelected11+numberNoYesOptional. Default selected pattern.
patterns11+Array<Pattern>NoNoMandatory. Resource of the pattern option.
action9+functionNoNoMandatory. Callback invoked when the pattern option changes.

Pattern

System capability: SystemCapability.MiscServices.InputMethodFramework

NameTypeRead-OnlyOptionalDescription
icon11+ResourceNoNoMandatory. Default icon.
selectedIcon11+ResourceNoNoMandatory. Icon for the selected option.

Events

The universal events are not supported.

Example

import { InputMethodListDialog, Pattern, PatternOptions } from '@kit.IMEKit';

@Entry
// Configure the component.
@Component
export struct settingsItem {
  @State defaultPattern: number = 1;
  private oneHandAction: PatternOptions = {
    defaultSelected: this.defaultPattern,
    patterns: [
      {
        icon: $r('app.media.hand_icon'),
        selectedIcon: $r('app.media.hand_icon_selected')
      },
      {
        icon: $r('app.media.hand_icon1'),
        selectedIcon: $r('app.media.hand_icon_selected1')
      },
      {
        icon: $r('app.media.hand_icon2'),
        selectedIcon: $r('app.media.hand_icon_selected2'),
      }],
    action:(index: number)=>{
      console.info(`pattern is changed, current is ${index}`);
      this.defaultPattern = index;
    }
  };
  private listController: CustomDialogController = new CustomDialogController({
    builder: InputMethodListDialog({ patternOptions: this.oneHandAction }),
    customStyle: true,
    maskColor: '#00000000'
  });

  build() {
    Column() {
      Flex({ direction: FlexDirection.Column,
        alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
        Text("Input Method List").fontSize(20)
      }
    }
    .width("13%")
    .id('bindInputMethod')
    .onClick((event?: ClickEvent) => {
      this.listController.open();
    })
  }
}

Effect Effect

你可能感兴趣的鸿蒙文章

harmony 鸿蒙IME Kit

harmony 鸿蒙InputMethod

harmony 鸿蒙Input Method Framework Error Codes

harmony 鸿蒙inputmethod_attach_options_capi.h

harmony 鸿蒙inputmethod_controller_capi.h

harmony 鸿蒙inputmethod_cursor_info_capi.h

harmony 鸿蒙inputmethod_inputmethod_proxy_capi.h

harmony 鸿蒙inputmethod_private_command_capi.h

harmony 鸿蒙inputmethod_text_avoid_info_capi.h

harmony 鸿蒙inputmethod_text_config_capi.h

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/z58Cjf