HarmonyOS Image 点击问题

Image正常显示的图片A,我在点击的时候想让Image显示图片B,点击结束又显示图片A(模拟button的点击效果),这个具体怎么实现呢

HarmonyOS
2024-12-25 11:14:26
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

可以参考此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%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
分享
微博
QQ
微信
回复
2024-12-25 14:16:01
相关问题
HarmonyOS Image点击无法全屏预览
498浏览 • 1回复 待解决
HarmonyOS Image问题咨询
840浏览 • 1回复 待解决
HarmonyOS image resizable问题咨询
1517浏览 • 1回复 待解决
HarmonyOS image组件拖拽问题
1200浏览 • 1回复 待解决
HarmonyOS image.createPixelMap使用问题
971浏览 • 1回复 待解决
HarmonyOS 防重复点击问题
629浏览 • 1回复 待解决
HarmonyOS 方法点击跳转问题
672浏览 • 1回复 待解决
HarmonyOS 点击事件监听问题
810浏览 • 1回复 待解决
HarmonyOS 点击事件判定问题
853浏览 • 1回复 待解决
Image组件缓存清空问题
4849浏览 待解决
HarmonyOS Image 加载网络图片问题
1932浏览 • 1回复 待解决
HarmonyOS点击事件传递响应问题
661浏览 • 1回复 待解决
HarmonyOS点击文本实现问题
446浏览 • 1回复 待解决
HarmonyOS image.PixelMap保存到 相册问题
973浏览 • 1回复 待解决
HarmonyOS Canvas绘制image的API相关问题
766浏览 • 1回复 待解决
HarmonyOS 组件叠加阻拦点击事件问题
791浏览 • 1回复 待解决
HarmonyOS 气泡点击蒙层问题
928浏览 • 1回复 待解决
HarmonyOS Push点击冷启动跳转问题
1200浏览 • 1回复 待解决
panel组件点击区域问题
5563浏览 • 1回复 待解决
HarmonyOS 使用react-native中的Image问题
736浏览 • 1回复 待解决