通过 $r(‘app.type.name’) 的形式引用应用资源
- app代表是应用内resources目录中定义的资源
- type代表资源类型(或资源的存放位置),可取"color",“float”,“string”,“media”,“plural”
- name代表资源命名,定义资源时确定
引用rawfile下资源时使用 $rawfile(‘filename’) 的形式,当前 $rawfile 仅支持Image控件引用图片资源
filename 为rawfile目录下的文件相对路径,文件名需要包含后缀,路径开头不可以以 “/” 开头
@Entry
@Component
struct MyComponent {
@State src:any = $r('app.media.play')
change:boolean = true
build() {
Row() {
Column() {
Image(this.src).width(100).height(100).onClick(() => {
this.change = !this.change
if (this.change) {
this.src = $r('app.media.pause')
} else {
this.src = $r('app.media.play')
}
})
}.width('100%')
}.height('100%')
}
}