W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
Menu是菜單接口,一般用于鼠標(biāo)右鍵彈窗、點(diǎn)擊彈窗等。具體用法請參考Menu控制。
菜單需要調(diào)用bindMenu接口來實(shí)現(xiàn)。bindMenu響應(yīng)綁定組件的點(diǎn)擊事件,綁定組件后手勢點(diǎn)擊對應(yīng)組件后即可彈出。
- Button('click for Menu')
- .bindMenu([
- {
- value: 'Menu1',
- action: () => {
- console.info('handle Menu1 select')
- }
- }
- ])
當(dāng)默認(rèn)樣式不滿足開發(fā)需求時(shí),可使用@Builder自定義菜單內(nèi)容??赏ㄟ^bindMenu接口進(jìn)行菜單的自定義。
- @State select: boolean = true
- private iconStr: ResourceStr = $r("app.media.view_list_filled")
- private iconStr2: ResourceStr = $r("app.media.view_list_filled")
- @Builder
- SubMenu() {
- Menu() {
- MenuItem({ content: "復(fù)制", labelInfo: "Ctrl+C" })
- MenuItem({ content: "粘貼", labelInfo: "Ctrl+V" })
- }
- }
- @Builder
- MyMenu(){
- Menu() {
- MenuItem({ startIcon: $r("app.media.icon"), content: "菜單選項(xiàng)" })
- MenuItem({ startIcon: $r("app.media.icon"), content: "菜單選項(xiàng)" }).enabled(false)
- MenuItem({
- startIcon: this.iconStr,
- content: "菜單選項(xiàng)",
- endIcon: $r("app.media.arrow_right_filled"),
- // 當(dāng)builder參數(shù)進(jìn)行配置時(shí),表示與menuItem項(xiàng)綁定了子菜單。鼠標(biāo)hover在該菜單項(xiàng)時(shí),會顯示子菜單。
- builder: this.SubMenu.bind(this),
- })
- MenuItemGroup({ header: '小標(biāo)題' }) {
- MenuItem({ content: "菜單選項(xiàng)" })
- .selectIcon(true)
- .selected(this.select)
- .onChange((selected) => {
- console.info("menuItem select" + selected);
- this.iconStr2 = $r("app.media.icon");
- })
- MenuItem({
- startIcon: $r("app.media.view_list_filled"),
- content: "菜單選項(xiàng)",
- endIcon: $r("app.media.arrow_right_filled"),
- builder: this.SubMenu.bind(this)
- })
- }
- MenuItem({
- startIcon: this.iconStr2,
- content: "菜單選項(xiàng)",
- endIcon: $r("app.media.arrow_right_filled")
- })
- }
- }
通過bindContextMenu接口進(jìn)行菜單的自定義及菜單彈出的觸發(fā)方式:右鍵或長按。使用bindContextMenu彈出的菜單項(xiàng)是在獨(dú)立子窗口內(nèi)的,可顯示在應(yīng)用窗口外部。
- Button('click for Menu')
- .bindContextMenu(this.MyMenu, ResponseType.RightClick)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: