那曲檬骨新材料有限公司

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

鴻蒙ArkTS聲明式開發:跨平臺支持列表【組件標識】 通用屬性

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-06-06 15:51 ? 次閱讀

組件標識

id為組件的唯一標識,在整個應用內唯一。本模塊提供組件標識相關接口,可以獲取指定id組件的屬性,也提供向指定id組件發送事件的功能。

說明:
開發前請熟悉鴻蒙開發指導文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
從API Version 8開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。

屬性

名稱參數說明描述
idstring組件的唯一標識,唯一性由使用者保證。 默認值:'' 從API version 9開始,該接口支持在ArkTS卡片中使用。

接口

getInspectorByKey9+

getInspectorByKey(id: string): string

獲取指定id的組件的所有屬性,不包括子組件信息

此接口僅用于對應用的測試。

參數:

參數類型必填描述
idstring要獲取屬性的組件id。

返回值:

類型描述
string組件屬性列表的JSON字符串。

getInspectorTree9+

getInspectorTree(): Object

獲取組件樹及組件屬性。

此接口僅用于對應用的測試。

返回值:

類型描述
Object組件樹及組件屬性列表的JSON對象。

sendEventByKey9+

sendEventByKey(id: string, action: number, params: string): boolean

給指定id的組件發送事件。

此接口僅用于對應用的測試。

參數:

參數類型必填描述
idstring要觸發事件的組件的id。
actionnumber要觸發的事件類型,目前支持取值: - 點擊事件Click: 10 - 長按事件LongClick: 11。
paramsstring事件參數,無參數傳空字符串 ""。

返回值:

類型描述
boolean找不到指定id的組件時返回false,其余情況返回true。

sendTouchEvent9+

sendTouchEvent(event: TouchObject): boolean

發送觸摸事件。

此接口僅用于對應用的測試。

參數:

參數類型必填描述
event[TouchObject]觸發觸摸事件的位置,event參數見[TouchEvent]中TouchObject的介紹。

返回值:

類型描述
boolean事件發送失敗時返回false,其余情況返回true。

sendKeyEvent9+

sendKeyEvent(event: KeyEvent): boolean

發送按鍵事件。

此接口僅用于對應用的測試。

參數:

參數類型必填描述
event[KeyEvent]按鍵事件,event參數見[KeyEvent]介紹。

返回值:

類型描述
boolean事件發送失敗時時返回false,其余情況返回true。

sendMouseEvent9+

sendMouseEvent(event: MouseEvent): boolean

發送鼠標事件。

此接口僅用于對應用的測試。

參數:

參數類型必填描述
event[MouseEvent]鼠標事件,event參數見[MouseEvent]介紹。

返回值:

類型描述HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
boolean事件發送失敗時返回false,其余情況返回true。
新文檔.png

示例

// xxx.ets
class Utils {
  static rect_left
  static rect_top
  static rect_right
  static rect_bottom
  static rect_value

  //獲取組件所占矩形區域坐標
  static getComponentRect(key) {
    let strJson = getInspectorByKey(key)
    let obj = JSON.parse(strJson)
    console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj))
    let rectInfo = JSON.parse('[' + obj.$rect + ']')
    console.info("[getInspectorByKey] rectInfo is: " + rectInfo)
    this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
    this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
    this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
    this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
    return this.rect_value = {
      "left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
    }
  }
}

@Entry
@Component
struct IdExample {
  @State text: string = ''

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {

      Button() {
        Text('onKeyTab').fontSize(25).fontWeight(FontWeight.Bold)
      }.margin({ top: 20 }).backgroundColor('#0D9FFB')
      .onKeyEvent(() = > {
        this.text = "onKeyTab"
      })

      Button() {
        Text('click to start').fontSize(25).fontWeight(FontWeight.Bold)
      }.margin({ top: 20 })
      .onClick(() = > {
        console.info(getInspectorByKey("click"))
        console.info(JSON.stringify(getInspectorTree()))
        this.text = "Button 'click to start' is clicked"
        setTimeout(() = > {
          sendEventByKey("longClick", 11, "") // 向id為"longClick"的組件發送長按事件
        }, 2000)
      }).id('click')

      Button() {
        Text('longClick').fontSize(25).fontWeight(FontWeight.Bold)
      }.margin({ top: 20 }).backgroundColor('#0D9FFB')
      .gesture(
      LongPressGesture().onActionEnd(() = > {
        console.info('long clicked')
        this.text = "Button 'longClick' is longclicked"
        setTimeout(() = > {
          let rect = Utils.getComponentRect('onTouch') // 獲取id為"onTouch"組件的矩形區域坐標
          let touchPoint: TouchObject = {
            id: 1,
            x: rect.left + (rect.right - rect.left) / 2, // 組件中心點x坐標
            y: rect.top + (rect.bottom - rect.top) / 2, // 組件中心點y坐標
            type: TouchType.Down,
            screenX: rect.left + (rect.right - rect.left) / 2, // 組件中心點x坐標
            screenY: rect.left + (rect.right - rect.left) / 2, // 組件中心點y坐標
          }
          sendTouchEvent(touchPoint) // 發送觸摸事件
          touchPoint.type = TouchType.Up
          sendTouchEvent(touchPoint) // 發送觸摸事件
        }, 2000)
      })).id('longClick')

      Button() {
        Text('onTouch').fontSize(25).fontWeight(FontWeight.Bold)
      }.type(ButtonType.Capsule).margin({ top: 20 })
      .onClick(() = > {
        console.info('onTouch is clicked')
        this.text = "Button 'onTouch' is clicked"
        setTimeout(() = > {
          let rect = Utils.getComponentRect('onMouse') // 獲取id為"onMouse"組件的矩形區域坐標
          let mouseEvent: MouseEvent = {
            button: MouseButton.Left,
            action: MouseAction.Press,
            x: rect.left + (rect.right - rect.left) / 2, // 組件中心點x坐標
            y: rect.top + (rect.bottom - rect.top) / 2, // 組件中心點y坐標
            screenX: rect.left + (rect.right - rect.left) / 2, // 組件中心點x坐標
            screenY: rect.top + (rect.bottom - rect.top) / 2, // 組件中心點y坐標
            timestamp: 1,
            target: {
              area: {
                width: 1,
                height: 1,
                position: {
                  x: 1,
                  y: 1
                },
                globalPosition: {
                  x: 1,
                  y: 1
                }
              }
            },
            source: SourceType.Mouse,
            pressure: 1,
            tiltX: 1,
            tiltY: 1,
            sourceTool: SourceTool.Unknown
          }
          sendMouseEvent(mouseEvent) // 發送鼠標事件
        }, 2000)
      }).id('onTouch')

      Button() {
        Text('onMouse').fontSize(25).fontWeight(FontWeight.Bold)
      }.margin({ top: 20 }).backgroundColor('#0D9FFB')
      .onMouse(() = > {
        console.info('onMouse')
        this.text = "Button 'onMouse' in onMouse"
        setTimeout(() = > {
          let keyEvent: KeyEvent = {
            type: KeyType.Down,
            keyCode: 2049,
            keyText: 'tab',
            keySource: 4,
            deviceId: 0,
            metaKey: 0,
            timestamp: 0
          }
          sendKeyEvent(keyEvent) // 發送按鍵事件
        }, 2000)
      }).id('onMouse')

      Text(this.text).fontSize(25).padding(15)
    }
    .width('100%').height('100%')
  }
}

審核編輯 黃宇

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 組件
    +關注

    關注

    1

    文章

    517

    瀏覽量

    17922
  • 鴻蒙
    +關注

    關注

    57

    文章

    2392

    瀏覽量

    43050
收藏 人收藏

    評論

    相關推薦

    鴻蒙ArkTS聲明開發平臺支持列表【安全區域】

    通過expandSafeArea屬性支持組件擴展其安全區域。
    的頭像 發表于 06-13 22:20 ?578次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【安全區域】

    鴻蒙ArkTS聲明開發平臺支持列表【文本通用

    文本通用屬性目前只針對包含文本元素的組件,設置文本樣式。
    的頭像 發表于 06-13 15:09 ?541次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【文本<b class='flag-5'>通用</b>】

    鴻蒙ArkTS聲明開發平臺支持列表【觸摸熱區設置】觸摸交互控制

    適用于支持通用點擊事件、通用觸摸事件、通用手勢處理的組件
    的頭像 發表于 06-13 10:33 ?508次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【觸摸熱區設置】觸摸交互控制

    鴻蒙ArkTS聲明開發平臺支持列表【無障礙屬性通用屬性

    組件可以設置相應的無障礙屬性和事件來更好地使用無障礙能力。
    的頭像 發表于 06-11 17:30 ?436次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【無障礙<b class='flag-5'>屬性</b>】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表組件內容模糊】 通用屬性

    為當前組件提供內容模糊能力。 value: 內容模糊樣式。模糊樣式由模糊半徑、蒙版顏色、蒙版透明度、飽和度、亮度五個參數組成。 options: 可選參數,內容模糊選項。
    的頭像 發表于 06-10 18:32 ?681次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【<b class='flag-5'>組件</b>內容模糊】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【分布遷移標識通用屬性

    組件的分布遷移標識,指明了該組件在分布遷移場景下可以將特定狀態恢復到對端設備。
    的頭像 發表于 06-07 21:15 ?441次閱讀

    鴻蒙ArkTS聲明開發平臺支持列表【多態樣式】 通用屬性

    設置組件不同狀態的樣式。 從API version 9開始,該接口支持ArkTS卡片中使用。
    的頭像 發表于 06-07 09:48 ?454次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【多態樣式】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【菜單控制】 通用屬性

    組件綁定彈出菜單,彈出菜單以垂直列表形式顯示菜單項,可通過長按、點擊或鼠標右鍵觸發。
    的頭像 發表于 06-06 09:17 ?764次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【菜單控制】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【柵格設置】 通用屬性

    默認占用列數,指useSizeType屬性沒有設置對應尺寸的列數(span)時,占用的柵格列數。
    的頭像 發表于 06-05 09:28 ?441次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【柵格設置】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【顏色漸變】 通用屬性

    設置組件的顏色漸變效果。
    的頭像 發表于 06-05 09:17 ?743次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【顏色漸變】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【形狀裁剪】 通用屬性

    參數為相應類型的組件,按指定的形狀對當前組件進行裁剪;參數為boolean類型時,設置是否按照父容器邊緣輪廓進行裁剪。 默認值:false 從API version 9開始,該接口支持Ark
    的頭像 發表于 06-04 15:22 ?517次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【形狀裁剪】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【顯隱控制】 通用屬性

    控制當前組件顯示或隱藏。注意,即使組件處于隱藏狀態,在頁面刷新時仍存在重新創建過程,因此當對性能有嚴格要求時建議使用[條件渲染]代替。 默認值:Visibility.Visible 從API version 9開始,該接口支持
    的頭像 發表于 06-03 14:46 ?640次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【顯隱控制】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【Flex布局】 通用屬性

    從API Version 7開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。 > - 僅當父組件是 Flex、Column、Row 、GridRow時生效。
    的頭像 發表于 05-30 14:38 ?682次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【Flex布局】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【布局約束】 通用屬性

    通過組件的寬高比和顯示優先級約束組件顯示效果。
    的頭像 發表于 05-30 09:35 ?401次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【布局約束】 <b class='flag-5'>通用</b><b class='flag-5'>屬性</b>

    鴻蒙ArkTS聲明開發平臺支持列表【按鍵事件】

    按鍵事件指組件與鍵盤、遙控器等按鍵設備交互時觸發的事件,適用于所有可獲焦組件,例如Button。對于Text,Image等默認不可獲焦的組件,可以設置focusable屬性為true后
    的頭像 發表于 05-28 18:12 ?919次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>開發</b>:<b class='flag-5'>跨</b><b class='flag-5'>平臺</b><b class='flag-5'>支持</b><b class='flag-5'>列表</b>【按鍵事件】
    威尼斯人娱乐城送38| 乐百家娱乐| 澳门百家乐官网赌客| 澳门百家乐现场游戏| 鸿利国际| 广发百家乐官网的玩法技巧和规则| A8百家乐的玩法技巧和规则| 名仕国际棋牌官方网| 老虎百家乐官网的玩法技巧和规则 | 百家乐发牌靴8| 网上百家乐官网娱乐场| 百家乐手机版| 东乡族自治县| 在线百家乐技巧| 孝昌县| 百家乐足球投注网哪个平台网址测速最好 | 百家乐官网韩泰阁| 全讯网官网| 百家乐官网路单怎样| 大发888官方sscptdf88yb| 百家乐官网赢足球博彩皇冠| 新东泰百家乐的玩法技巧和规则| 澳门百家乐官网怎么看小路| 二八杠自行车| 百家乐官网游戏机的玩法| 尊龙百家乐娱乐场开户注册| 百家乐官网棋牌作弊器| 威尼斯人娱乐网注册网址| 游戏机百家乐官网的技巧| 大发888游戏官方下载客户端 | 大发888游戏平台 娱乐场下载| 百家乐官网桌子轮盘| 大发888下注| 网上百家乐洗码技巧| 百家乐官网的技术与心态| 太阳城金旭园| 葡京百家乐注码| 桦甸市| 网络百家乐赚| 百家乐官网娱乐分析软件v| 贵南县|