arkts harmonyos中要使用剪贴板实现复制黏贴功能的话我们可以调用系统的剪切板模块@ohos.pasteboard (剪贴板)
harmonyOS 入门免费实战系列教程:
HarmonyOS HarmonyOS Next系列教程下载地址-IT营大地老师
arkts harmonyos 使用剪贴板实现复制黏贴功能完整代码
Row() {
Text("复制").fontSize("44lpx").fontColor(Color.Gray).onClick(() => {
const shardedUrl = "1233333"
const pasteboardData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, shardedUrl)
const systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.setData(pasteboardData)
})
Text("获取").fontSize("44lpx").fontColor(Color.Gray).onClick(() => {
const systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.getPasteData().then((data) => {
promptAction.showToast({ message: data.getPrimaryText(), bottom: 50 })
})
})
}.justifyContent(FlexAlign.SpaceBetween)
.margin({ top: "60lpx" })
.width("90%")
.height("60lpx")