如何实现悬浮窗桌面穿透

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

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%') 
  } 
}

适配的版本信息

 IDE:DevEco Studio 4.0.3.600

 SDK:HarmoneyOS 4.0.10.11

分享
微博
QQ
微信
回复
2024-05-27 19:45:55
相关问题
HarmonyOS 如何在PaasSDK内部实现悬浮
908浏览 • 1回复 待解决
HarmonyOS 横向悬浮
1038浏览 • 1回复 待解决
HarmonyOS 是否支持悬浮能力
1041浏览 • 1回复 待解决
基于子窗口实现应用内悬浮
1532浏览 • 1回复 待解决
HarmonyOS 可拖动悬浮如何制作
906浏览 • 1回复 待解决
HarmonyOS 如何跨模块启动悬浮
1010浏览 • 1回复 待解决
HarmonyOS 如何支持全局的悬浮
3760浏览 • 1回复 待解决
HarmonyOS 悬浮的圆角怎么处理?
1418浏览 • 1回复 待解决
HarmonyOS 如何实现事件穿透
653浏览 • 1回复 待解决
横屏应用如何适配华为悬浮?
3749浏览 • 1回复 待解决
HarmonyOS有没有悬浮组件或者库
1248浏览 • 1回复 待解决
使用悬浮和端内want唤醒APP
1873浏览 • 1回复 待解决