arkts harmonyos 使用剪贴板实现复制黏贴功能
arkts harmonyos中要使用剪贴板实现复制黏贴功能的话我们可以调用系统的剪切板模块@ohos.pasteboard (剪贴板)
harmonyOS 入门免费实战系列教程:https://www.itying.com/goods-1193.html
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")