奶油小蛋高|
HarmonyOS 5
Image 点击问题
Image正常显示的图片A,我在点击的时候想让Image显示图片B,点击结束又显示图片A(模拟button的点击效果),这个具体怎么实现呢
2
浏览202 发布于2025-02-20 03:16广东
全部评论
最多点赞
最新发布
最早发布
哈希魔术师技术支持
可以参考此demo:
收起
自动换行
深色代码主题
复制
@Entry
@Component
struct ImageExample3 {
private imageOne: Resource = $r('app.media.1');
private imageTwo: Resource = $r('app.media.2');
@State src: Resource = this.imageOne
@State eventType: string = '事件'
build(){
Column(){
Text(this.eventType)
.margin(20)
Image(this.src)
.width(100)
.height(100)
.onTouch((event?: TouchEvent) => {
if(event){
if (event.type === TouchType.Down) {
this.eventType = 'Down'
this.src = this.imageTwo
}
if (event.type === TouchType.Up) {
this.eventType = 'Up'
this.src = this.imageOne
}
}
})
}.width('100%').height('100%')
}
}2楼回复于2025-02-20 06:18 来自广东
windraxb可以试一下图片加载使用背景图片加载,然后用多态样式设置按下的图片
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-polymorphic-style-V5
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-polymorphic-style-V5
1楼回复于2025-02-20 03:28 来自浙江
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
相关推荐
换一批
1
HarmonyOS Image加载在线jpeg图片闪退 (API12+)
2
HarmonyOS 如何通过ColorFilter设置Image中黑色变白色?(API12+)
3
HarmonyOS backgroundImage加载网络图片,是否可以判断图片加载完成 (API12+)
4
HarmonyOS Image加载rawfile目录下的图片,编译的时候报找不到该资源 (API12+)
5
ListItem的style动态切换时,实际渲染效果不会跟随变化
6
HarmonyOS 如何实现在图片中间新增一个播放图片按钮 (API12+)
7
如何显示图片预览通知
8
如何通过帧动画的形式实现点击tab时的图标动画效果
了解社区公约,与您携手共创和谐专业的开发者社区。




































苏公安网备 32011402010933号