垂直列表形式顯示的菜單

2024-01-22 17:15 更新

以垂直列表形式顯示的菜單。

說明
  • 該組件從API Version 9開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。
  • Menu組件需和bindMenubindContextMenu方法配合使用,不支持作為普通組件單獨使用。

子組件

包含MenuItem、MenuItemGroup子組件。

接口

Menu()

作為菜單的固定容器,無參數(shù)。

屬性

除支持通用屬性外,還支持以下屬性:

名稱

參數(shù)類型

描述

fontSize

Length

統(tǒng)一設(shè)置Menu中所有文本的尺寸,Length為number類型時,使用fp單位。

示例

  1. @Entry
  2. @Component
  3. struct Index {
  4. @State select: boolean = true
  5. private iconStr: ResourceStr = $r("app.media.view_list_filled")
  6. private iconStr2: ResourceStr = $r("app.media.view_list_filled")
  7. @Builder
  8. SubMenu() {
  9. Menu() {
  10. MenuItem({ content: "復(fù)制", labelInfo: "Ctrl+C" })
  11. MenuItem({ content: "粘貼", labelInfo: "Ctrl+V" })
  12. }
  13. }
  14. @Builder
  15. MyMenu(){
  16. Menu() {
  17. MenuItem({ startIcon: $r("app.media.icon"), content: "菜單選項" })
  18. MenuItem({ startIcon: $r("app.media.icon"), content: "菜單選項" })
  19. .enabled(false)
  20. MenuItem({
  21. startIcon: this.iconStr,
  22. content: "菜單選項",
  23. endIcon: $r("app.media.arrow_right_filled"),
  24. builder: this.SubMenu.bind(this)
  25. })
  26. MenuItemGroup({ header: '小標(biāo)題' }) {
  27. MenuItem({ content: "菜單選項" })
  28. .selectIcon(true)
  29. .selected(this.select)
  30. .onChange((selected) => {
  31. console.info("menuItem select" + selected);
  32. this.iconStr2 = $r("app.media.icon");
  33. })
  34. MenuItem({
  35. startIcon: $r("app.media.view_list_filled"),
  36. content: "菜單選項",
  37. endIcon: $r("app.media.arrow_right_filled"),
  38. builder: this.SubMenu.bind(this)
  39. })
  40. }
  41. MenuItem({
  42. startIcon: this.iconStr2,
  43. content: "菜單選項",
  44. endIcon: $r("app.media.arrow_right_filled")
  45. })
  46. }
  47. }
  48. build() {
  49. Row() {
  50. Column() {
  51. Text('click to show menu')
  52. .fontSize(50)
  53. .fontWeight(FontWeight.Bold)
  54. }
  55. .bindMenu(this.MyMenu)
  56. .width('100%')
  57. }
  58. .height('100%')
  59. }
  60. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號