Compose 封装 - 禁止截屏
2026/7/4 3:33:02 网站建设 项目流程

一、封装成Modifier

/** * 当前界面不允许截屏,退出该界面后恢复 */ @Composable fun Modifier.secureScreen(enable: Boolean = true): Modifier = composed { val context = LocalContext.current DisposableEffect(Unit) { if (enable) { (context as? Activity)?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE) } else { (context as? Activity)?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) } onDispose { (context as? Activity)?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) } } this }

二、封装成可组合项

/** * 当前界面不允许截屏,退出该界面后恢复 */ @Composable fun SecureScreen(enable: Boolean = true) { val context = LocalContext.current DisposableEffect(Unit) { if (enable) { (context as? Activity)?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE) } else { (context as? Activity)?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) } onDispose { (context as? Activity)?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) } } }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询