如何实现悬浮窗桌面穿透

悬浮窗设置不聚焦不触摸,设置半透明,可以穿透操作。

HarmonyOS
2024-05-26 14:33:51
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
e_leaner

使用的核心API

窗口管理

核心代码解释

import display from '@ohos.display'; 
import window from '@ohos.window'; 
import Prompt from '@system.prompt'; 
  
@Entry 
@Component 
struct Index { 
  @State screenWidth: number = 0; 
  @State screenHeight: number = 0; 
  
  aboutToAppear() { 
    this.screenWidth = display.getDefaultDisplaySync().width; 
    this.screenHeight = display.getDefaultDisplaySync().height; 
  } 
  
  build() { 
    Row() { 
      Button("弹窗") 
        .onClick(() => { 
          window.createWindow({ name: "screenDialog", windowType: window.WindowType.TYPE_FLOAT, ctx: getContext(this) }) 
            .then((r) => { 
              r.setUIContent("pages/ScreenPage2").then(() => { 
                r.setWindowBackgroundColor("#00000000") 
                r.resize(this.screenWidth, this.screenHeight).then(() => { 
                  r.showWindow().then(() => { 
                    r.getWindowProperties().isTransparent = true; 
                    r.setWindowTouchable(false) 
                    r.setWindowFocusable(false) 
                  }); 
                }); 
              }); 
            }) 
        }) 
  
      Button("应用内点击").onClick(() => { 
        Prompt.showToast({ message: "应用内点击" }) 
      }) 
    }.justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center) 
    .height('100%').width('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.

适配的版本信息

 IDE:DevEco Studio 4.0.3.600

 SDK:HarmoneyOS 4.0.10.11

分享
微博
QQ
微信
回复
2024-05-27 19:45:55
相关问题
HarmonyOS 如何在PaasSDK内部实现悬浮
732浏览 • 1回复 待解决
HarmonyOS 横向悬浮
753浏览 • 1回复 待解决
基于子窗口实现应用内悬浮
1262浏览 • 1回复 待解决
HarmonyOS 如何跨模块启动悬浮
822浏览 • 1回复 待解决
HarmonyOS 可拖动悬浮如何制作
662浏览 • 1回复 待解决
HarmonyOS 如何支持全局的悬浮
2225浏览 • 1回复 待解决
HarmonyOS 是否支持悬浮能力
863浏览 • 1回复 待解决
HarmonyOS 如何实现事件穿透
475浏览 • 1回复 待解决
横屏应用如何适配华为悬浮?
3542浏览 • 1回复 待解决
HarmonyOS 悬浮的圆角怎么处理?
1108浏览 • 1回复 待解决
HarmonyOS有没有悬浮组件或者库
1067浏览 • 1回复 待解决
HarmonyOS 悬浮拖拽功能怎么处理?
1375浏览 • 1回复 待解决