超链接组件,支持文本和图片两种展示形式,在组件宽高范围内点击可实现跳转到指定网页。适用于应用内打开外部网页链接的场景,该组件仅支持与系统浏览器配合使用。
Hyperlink(address: string | Resource, content?: string | Resource)
元服务API: 从API version 11开始,该接口支持在元服务中使用。
系统能力: SystemCapability.ArkUI.ArkUI.Full
参数:
color(value: Color | number | string | Resource)
设置超链接文本的颜色。
元服务API: 从API version 11开始,该接口支持在元服务中使用。
系统能力: SystemCapability.ArkUI.ArkUI.Full
参数:
该示例展示了超链接图片和文本跳转的效果。
@Entry
@Component
struct HyperlinkExample {
build() {
Column() {
Column() {
Hyperlink('https://example.com/') {
// $r('app.media.bg')需要替换为开发者所需的图像资源文件。
Image($r('app.media.bg'))
.width(200)
.height(100)
}
}
Column() {
Hyperlink('https://example.com/', 'Go to the developer website')
.color(Color.Blue)
}
}.width('100%').height('100%').justifyContent(FlexAlign.Center)
}
} 