需要在Scroll组件里有一个onClick,否则无法成功获得焦点

这样没有onClick是不行的

import { LengthMetrics } from '@kit.ArkUI'

@Entry
@ComponentV2
struct Index {
  private scrollerForScroll: Scroller = new Scroller()

  build() {
    Flex() {
      Scroll(this.scrollerForScroll) {
        Column() {
          Text("Scroll Area")
            .width("100%")
            .height("200fp")
            .backgroundColor(0X330000FF)
            .fontSize(16)
            .textAlign(TextAlign.Center)

          Text("Scroll Area")
            .width("100%")
            .height("200fp")
            .backgroundColor(0X330000FF)
            .fontSize(16)
            .textAlign(TextAlign.Center)
        }
      }
      .focusable(true)
      .defaultFocus(true)
      .focusOnTouch(true)
      .edgeEffect(EdgeEffect.Spring)
      .width("100%").height("100%")
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20)
  }
}

这样有onClick是可以的

import { LengthMetrics } from '@kit.ArkUI'

@Entry
@ComponentV2
struct Index {
  private scrollerForScroll: Scroller = new Scroller()

  build() {
    Flex() {
      Scroll(this.scrollerForScroll) {
        Column() {
          Text("Scroll Area")
            .width("100%")
            .height("200fp")
            .backgroundColor(0X330000FF)
            .fontSize(16)
            .textAlign(TextAlign.Center)
            .onClick(() => {

            })

          Text("Scroll Area")
            .width("100%")
            .height("200fp")
            .backgroundColor(0X330000FF)
            .fontSize(16)
            .textAlign(TextAlign.Center)
        }
      }
      .focusable(true)
      .defaultFocus(true)
      .focusOnTouch(true)
      .edgeEffect(EdgeEffect.Spring)
      .width("100%").height("100%")
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20)
  }
}
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐