如何设置Toast通知居中显示并适配多分辨率(PowerShell)
实现Toast通知屏幕居中显示(适配全分辨率)
默认Windows Toast通知固定显示在屏幕右下角,要让它居中显示且适配1024x768等各种分辨率,需要通过自定义Toast XML控制布局参数——BurntToast模块原生命令不支持直接设置居中属性,以下是修改后的实现脚本:
# 构造带居中参数的Toast XML内容,同时适配分辨率 $toastXml = @" <toast scenario="incomingCall" launch="action=viewCall"> <audio silent="true"/> <visual> <binding template="ToastGeneric" hint-horizontalAlignment="center" hint-verticalAlignment="center" hint-maxWidth="364"> <text>......message......</text> <image placement="hero" src="C:\Logo\Autopilot.jpg"/> <image placement="appLogoOverride" hint-crop="circle" src="C:\Logo\AutopilotAppLogo.jpg"/> </binding> </visual> </toast> "@ # 转换XML并发送通知 $xmlDoc = New-Object System.Xml.XmlDocument $xmlDoc.LoadXml($toastXml) $toastManager = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::GetDefault() $notification = [Windows.UI.Notifications.ToastNotification]::new($xmlDoc) $toastManager.CreateToastNotifier("PowerShell").Show($notification)
关键配置说明:
hint-horizontalAlignment="center"+hint-verticalAlignment="center":强制Toast在屏幕水平、垂直方向居中hint-maxWidth="364":限制Toast最大宽度为Windows标准Toast宽度,避免在1024x768等低分辨率屏幕上超出显示范围- 保留原脚本的静音、来电场景、图片配置,确保功能逻辑一致
适配保证:
系统会根据当前屏幕分辨率自动调整Toast的显示尺寸,上述布局在1024x768及更高分辨率下均能保持居中且内容完整显示。
内容的提问来源于stack exchange,提问作者Arbelac
相关产品推荐
相关产品推荐

