openharmony 鸿蒙 ohos-atomicservice-AtomicServiceMenuBar-sys

2026-08-25 浏览 (1)

AtomicServiceMenuBar (系统接口)

依赖当前元服务的上下文,创建AtomicServiceMenuBar对象,用于操控右上角菜单功能胶囊的显示与隐藏。

说明:

该组件从API version 23开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

导入模块

import { AtomicServiceMenuBar } from '@kit.ArkUI';

子组件

属性

不支持通用属性

AtomicServiceMenuBar

使用当前元服务的UI上下文信息创建的对象,通过定义的接口操控当前元服务菜单功能胶囊的状态。示例参见示例

constructor

constructor(uiContext: UIContext)

AtomicServiceMenuBar的构造函数。

原子化服务API: 从API version 23开始,该接口支持在原子化服务中使用。

模型约束: 此接口仅可在Stage模型下使用。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名类型必填说明
uiContextUIContext当前元服务的上下文信息。

setVisible

setVisible(visible: boolean): void

设置当前元服务菜单功能胶囊的显隐状态。

原子化服务API: 从API version 23开始,该接口支持在原子化服务中使用。

模型约束: 此接口仅可在Stage模型下使用。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名类型必填说明
visibleboolean菜单功能胶囊预期的状态。true表示显示菜单功能胶囊,false表示隐藏菜单功能胶囊。

示例

import { AtomicServiceMenuBar } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  private menuBar: AtomicServiceMenuBar = new AtomicServiceMenuBar(this.getUIContext());

  @Builder
  private EmbedCompLauncherShow(title: string, text: string, event?: () => void) {
    Column() {
      if (typeof event === 'function') {
        Button(title)
          .width(300)
          .height(50)
          .fontSize(16)
          .borderRadius(25)
          .onClick(() => {
            event();
          })
      }
      Text(`预期现象:${text}`)
        .width(300)
        .textAlign(TextAlign.Start)
        .fontSize(12)
        .margin({ top: 5, bottom: 15})
    }
  }

  build() {
    Column() {
      this.EmbedCompLauncherShow('显示菜单功能胶囊', '点击后菜单功能胶囊显示', () => {
        this.menuBar.setVisible(true);
      });
      this.EmbedCompLauncherShow('隐藏菜单功能胶囊', '点击后菜单功能胶囊消失', () => {
        this.menuBar.setVisible(false);
      });
    }
    .width('100%')
    .height('100%')
    .padding({ top: 100 })
  }
}

点击“隐藏菜单功能胶囊”按钮后,菜单功能胶囊隐藏。

AtomicServiceMenuBarDemo01

点击“显示菜单功能胶囊”按钮后,菜单功能胶囊显示。

AtomicServiceMenuBarDemo02

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 ts-drawing-components-shape

openharmony 鸿蒙 ts-universal-attributes-sharp-clipping

openharmony 鸿蒙 ts-universal-attributes-toolbar

openharmony 鸿蒙 ts-container-lazyvgridlayout

openharmony 鸿蒙 ohos-arkui-advanced-FoldSplitContainer

openharmony 鸿蒙 ts-methods-calendarpicker-dialog

openharmony 鸿蒙 ts-uicommonevent

openharmony 鸿蒙 ts-basic-gestures-tapgesture

openharmony 鸿蒙 ohos-arkui-advanced-DialogV2

openharmony 鸿蒙 ts-components-canvas-canvas

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/EoMEyBW0