长按文字出现的复制菜单,在swiper滑走后,依然残留

长按文字出现的复制菜单,在swiper滑走后,依然残留。

以下是最小demo。

@Entry  
@Component  
struct CopyPage {  
  @State message: string = '长按我,出现复制菜单,然后左右滑动,菜单没消失';  
  @Builder demoBuilder(){  
    Text(this.message)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .layoutWeight(1)  
      .copyOption(CopyOptions.LocalDevice)  
  }  
  build() {  
    Row() {  
      Column() {  
        Swiper() {  
          ForEach([1,1,1,1,1,1,1,1,1,1,1,1], () => {  
            this.demoBuilder()  
          })  
        }  
        .layoutWeight(1)  
      }  
      .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.
HarmonyOS
2024-10-11 11:43:25
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

closeSelectionMenu方法可以关闭菜单,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-text-V5

参考demo:

@Component  
struct demoBuilder{  
  @Prop message: string;  
  @Link @Watch('onChange') currentIndex: number;  
  onChange(){  
    this.tController.closeSelectionMenu()  
  }  
  private tController: TextController = new TextController();  
  build(){  
    Text(this.message, {controller: this.tController})  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .layoutWeight(1)  
      .copyOption(CopyOptions.LocalDevice)  
  }  
}  
@Entry  
@Component  
struct CopyPage {  
  @State message: string = '长按我,出现复制菜单,然后左右滑动,菜单没消失';  
  @State currentIndex:number = 0;  
  build() {  
    Row() {  
      Column() {  
        Swiper(this.swiperController) {  
          ForEach([1,1,1,1,1,1,1,1,1,1,1,1], (item:number, index:number) => {  
            demoBuilder({message: this.message, currentIndex: this.currentIndex});  
          })  
        }  
        .layoutWeight(1)  
        .onChange((index:number)=>{  
          this.currentIndex = index;  
        })  
      }  
      .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.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
分享
微博
QQ
微信
回复
2024-10-11 16:20:37


相关问题
Navigation设置隐藏依然出现空白导航栏
2450浏览 • 1回复 待解决
HarmonyOS 长按桌面图标展开菜单
507浏览 • 1回复 待解决