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%') 
    } 
  } 
}

效果如图所示:

分享
微博
QQ
微信
回复
2024-03-18 20:21:11
相关问题
Text组件是否支持小图片和表情
860浏览 • 1回复 待解决
有谁知道是否支持Emoj表情
897浏览 • 1回复 待解决
ArkUI 支持 Tcp Server吗?
2008浏览 • 1回复 待解决
ArkUI组件能否支持继承
641浏览 • 1回复 待解决
emoji字符串无法进行截取
517浏览 • 1回复 待解决
是否支持iconfont?是否有样例代码?
531浏览 • 1回复 待解决
innerHTML 是否支持
1715浏览 • 1回复 待解决
webview是否支持CodeCache
430浏览 • 1回复 待解决
webview是否支持预览pdf
499浏览 • 1回复 待解决
鸿蒙是否支持加载HTML
11254浏览 • 3回复 待解决
Swiper是否支持组件复用
396浏览 • 1回复 待解决
Webview是否支持定位功能?
410浏览 • 1回复 待解决
是否支持CFCA证书预置
195浏览 • 1回复 待解决
HarmonyOS是否支持消息推送?
645浏览 • 1回复 待解决