可以添加一个定时器,到时间后就会执行需要的操作,示例如下:@Entry @Component export struct BookingBallFieldItemView { @State item: string = 'xxxx' @State detailIsShow: Visibility = Visibility.None fontStyleAttr1: TextStyle = new TextStyle({ fontColor: '#ffae18ff' }); mutableStyledString1: MutableStyledString = new MutableStyledString(this.item, [{ start: 2, length: 1, styledKey: StyledStringKey.FONT, styledValue: this.fontStyleAttr1 }]); controller2: TextController = new TextController(); async onPageShow() { this.controller2.setStyledString(this.mutableStyledString1) } build() { Column() { Row() { Column() { Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Start }) { Text(undefined, { controller: this.controller2 }) .fontColor('#333333') .fontSize(16) .maxLines(1) .height(20) .textAlign(TextAlign.Start) .textOverflow({ overflow: TextOverflow.Ellipsis }) .key('mutableStyledString1') .onClick(() => { setTimeout(() => { this.detailIsShow = Visibility.Visible }, 3000) }) Text('玄幻小说').visibility(this.detailIsShow).margin({ left: 30 }) }.width("100%") } .layoutWeight(1) .margin({ left: 15, top: 12 }) .alignItems(HorizontalAlign.Start) .justifyContent(FlexAlign.Start) }.width('100%').justifyContent(FlexAlign.Start) } } }
可以添加一个定时器,到时间后就会执行需要的操作,示例如下: