ArkUI是否支持emoji表情输入

ArkUI是否支持emoji表情输入

HarmonyOS
2024-03-17 14:38:08
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
chmqn

通过RichEditor组件加自定义键盘实现emoji表情输入。可参考如下代码:

// xxx.ets 
@Entry 
@Component 
struct RichEditorExample { 
  controller: RichEditorController = new RichEditorController() 
  private listData: (string | number | Resource)[] = [ 
    $r('app.media.ic_add'), 
    $r('app.media.ic_address'), 
    $r('app.media.icon'), 
    1,   
    2, 
    3, 
    String.fromCodePoint(0x1F600), 
    String.fromCodePoint(0x1F600), 
    String.fromCodePoint(0x1F600) 
  ]; 
 
  // 自定义键盘组件 
  @Builder 
  CustomKeyboardBuilder() { 
    Column() { 
      Grid() { 
        ForEach(this.listData, (item: string | number | Resource) => { 
          GridItem() { 
            if (typeof item === 'number' || typeof item === 'string') { 
              Button(item + '') 
                .width(110) 
                .onClick(() => { 
                  this.controller.addTextSpan(item + '', { 
                    offset: this.controller.getCaretOffset(), 
                    style: { fontColor: Color.Orange, fontSize: 30 } 
                  }) 
                  this.controller.setCaretOffset(this.controller.getCaretOffset() + item.toString().length) 
                }) 
            } else { 
              Image(item) 
                .width(110) 
                .onClick(() => { 
                  this.controller.addImageSpan(item, { imageStyle: { size: ['110px', '110px'] } }) 
                }) 
            } 
          } 
        }) 
      } 
      .maxCount(3) 
      .columnsGap(10) 
      .rowsGap(10) 
      .padding(5) 
    } 
    .width('100%') 
    .backgroundColor(Color.Gray) 
  } 
 
  build() { 
    Column() { 
      RichEditor({ controller: this.controller })// 绑定自定义键盘 
        .customKeyboard(this.CustomKeyboardBuilder()) 
        .margin(10) 
        .border({ width: 1 }) 
        .height(200) 
        .borderWidth(1) 
        .borderColor(Color.Red) 
        .width('100%') 
    } 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.

效果如图所示:

分享
微博
QQ
微信
回复
2024-03-18 20:21:11
相关问题
TextInput如何禁止输入emoj表情
1413浏览 • 1回复 待解决
ArkUI 是否支持iconfont
1001浏览 • 0回复 待解决
有谁知道是否支持Emoj表情
2806浏览 • 1回复 待解决
Text组件是否支持小图片和表情
3040浏览 • 1回复 待解决
HarmonyOS 如何支持表情和富文本
1788浏览 • 2回复 待解决
HarmonyOS 怎么绘制emoji
707浏览 • 1回复 待解决
ArkUI的触摸事件分为哪几类输入源?
223浏览 • 0回复 待解决
ArkUI组件能否支持继承
2391浏览 • 1回复 待解决
ArkUI 支持 Tcp Server吗?
4009浏览 • 1回复 待解决