HarmonyOS bindContextMenu中设置backgroundColor不生效

想改变menu弹框默认的背景色,发现设置backgroundColor无效;通过更改自定义menu根布局颜色的话,又无法做到填充满Menu的边角。

HarmonyOS
2024-11-27 09:47:21
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

修改弹出菜单颜色可参考如下实现方式:

@Entry 
@Component 
struct BindContextMenuTest { 
  @Builder 
  MsgMenuBuilder() { 
    Menu() { 
      MenuItem({content: "menu"}) 
        .contentFontColor(Color.Black) 
        .backgroundColor(Color.Green) 
        .labelFontColor(Color.Black) 
        .padding({ 
          left: 15, 
          right: 15, 
          top: 5, 
          bottom: 5 
        }) 
    }.backgroundColor(Color.Green) 
  } 
 
  build() { 
    Column() { 
      Text('Long Press Text') 
        .width(150) 
        .height(100) 
        .textAlign(TextAlign.Center) 
        .margin(100) 
        .fontSize(30) 
        .bindContextMenu(this.MsgMenuBuilder, ResponseType.LongPress, { 
          enableArrow: true, 
          placement: Placement.Bottom, 
          backgroundColor: "#2A2C2D", 
          preview: MenuPreviewMode.IMAGE, 
          previewAnimationOptions: {scale: [0.8, 1.0]} 
 
        }) 
    }.width('100%').backgroundColor(Color.Pink) 
  } 
} 
 
//bindContextMenu的箭头颜色无法设置,建议使用bindPopup替代bindContextMenu,并将 backgroundBlurStyle属性设为BlurStyle.NONE,可参考如下示例代码: 
 
@Entry 
@Component 
struct BindPopUpTest { 
  @State customPopup: boolean = false; 
 
  @Builder popupBuilder() { 
    Column({ space: 2 }) { 
      Menu() { 
        MenuItem({content: "menu1"}) 
          .backgroundColor(Color.White) 
          .margin({top: 5}) 
          .width("100%") 
        MenuItem({content: "menu2"}) 
          .backgroundColor(Color.White) 
          .margin({top: 5}) 
          .width("100%") 
      } 
    } 
    .justifyContent(FlexAlign.SpaceAround) 
    .width(200) 
    .height(125) 
    .padding(5) 
  } 
 
  build() { 
    Column() { 
      Text('LongPress') 
        .fontSize(28) 
        .gesture( 
          LongPressGesture({ repeat: true }) 
            .onAction((event: GestureEvent|undefined) => { 
              this.customPopup = !this.customPopup; 
            }) 
        ) 
        .bindPopup(this.customPopup, { 
          builder: this.popupBuilder, 
          placement: Placement.Bottom, 
          popupColor: Color.Green, 
          mask: false, 
          backgroundBlurStyle: BlurStyle.NONE, 
          enableArrow: true, 
          onStateChange: (e) => { 
            if (!e.isVisible) { 
              this.customPopup = false; 
            } 
          } 
        }) 
    } 
    .justifyContent(FlexAlign.Center) 
    .width('100%') 
    .height("100%") 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
分享
微博
QQ
微信
回复
2024-11-27 14:58:14


相关问题
ConstraintSize尺寸设置生效
2864浏览 • 1回复 待解决
HarmonyOS Panel 设置 borderRadius 生效
1459浏览 • 1回复 待解决
HarmonyOS stack设置圆角生效
664浏览 • 1回复 待解决
HarmonyOS Badge文本颜色设置生效
780浏览 • 1回复 待解决
通过WindowProperties设置属性生效
2590浏览 • 1回复 待解决
Tab 设置 barBackgroundColor为透明生效
540浏览 • 1回复 待解决
HarmonyOS 设置安全区域生效
495浏览 • 1回复 待解决
HarmonyOS 设置了icon和label生效
793浏览 • 1回复 待解决