HarmonyOS 鸿蒙Next元服务创建子窗口如何隐藏右上角胶囊?

HarmonyOS 鸿蒙Next元服务创建子窗口如何隐藏右上角胶囊? 想通过创建子窗口实现全局悬浮窗功能,但在元服务中创建后发现子窗口会带有元服务自带的右上角的胶囊,是否有方法隐藏子窗口上的胶囊?

2 回复
您好,右上角是平台常驻胶囊入口,不允许开发者进行处理的,这个入口不是开放能力。

可以通过使用navigation可自动实现避让,或通过ARKUI Inspector获取右上角胶囊的位置及大小。

以上是初步分析结论,如有疑问可以展开回复,看到后会继续协助定位阻碍点。

开源网站上收录了UI、系统接口、Web、创新特性等场景化鸿蒙示例DEMO,开发中可以参考:[https://gitee.com/scenario-samples/demo-index](https://gitee.com/scenario-samples/demo-index)

更多关于HarmonyOS 鸿蒙Next元服务创建子窗口如何隐藏右上角胶囊?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,创建子窗口时隐藏右上角胶囊可以通过以下步骤实现:

  1. 使用 WindowsetWindowSystemBarEnable 方法:通过调用 WindowsetWindowSystemBarEnable 方法,可以控制系统栏的显示与隐藏。将参数设置为 false 即可隐藏右上角的胶囊按钮。

    let windowClass = window.getTopWindow();
    windowClass.setWindowSystemBarEnable(false);
    
  2. 使用 WindowsetWindowLayoutFullScreen 方法:通过调用 setWindowLayoutFullScreen 方法,可以将窗口设置为全屏模式,从而隐藏系统栏和胶囊按钮。

    let windowClass = window.getTopWindow();
    windowClass.setWindowLayoutFullScreen(true);
    
  3. 使用 WindowsetWindowSystemBarProperties 方法:通过调用 setWindowSystemBarProperties 方法,可以自定义系统栏的属性,包括是否显示胶囊按钮。

    let windowClass = window.getTopWindow();
    windowClass.setWindowSystemBarProperties({
        navigationBarColor: "#000000",
        navigationBarContentColor: "#FFFFFF",
        statusBarColor: "#000000",
        statusBarContentColor: "#FFFFFF",
        isNavigationBarVisible: false
    });
    

以上方法可以根据具体需求选择使用,以实现隐藏右上角胶囊的效果。

回到顶部