代码拉取完成,页面将自动刷新
同步操作将从 astator/astator.examples 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using astator.Core.Script;
using astator.Core.UI.Base;
using astator.Core.UI.Floaty;
using System;
namespace Examples;
public class FloatyTest
{
[ScriptEntryMethod(FileName = "08.悬浮窗.cs", IsUIMode = true)]
public static void Main(ScriptRuntime runtime)
{
var ui = @"
<linear orientation='vertical'>
<card bg='#444f7d'>
<text margin='10,0' h='60' text='悬浮窗' textColor='#000000' textSize='22' textStyle='bold' gravity='center'/>
</card>
<linear orientation='vertical'>
<btn id='show' text='显示悬浮窗' margin='20,5'/>
<btn id='remove' text='移除悬浮窗' margin='20,5'/>
<btn id='setPosition' text='设置位置' margin='20,5'/>
</linear>
</linear>";
runtime.Ui.Show(runtime.Ui.ParseXml(ui));
SystemFloatyWindow floatyWindow = null;
runtime.Ui["show"].On("click", new OnClickListener((v) =>
{
if (!runtime.PermissionHelper.CheckFloaty())
{
runtime.PermissionHelper.ReqFloaty((isEnabled) =>
{
if (isEnabled) Globals.Toast("申请悬浮窗权限成功");
});
return;
}
else
{
floatyWindow?.Remove();
floatyWindow = null;
var xml = @"
<frame bg='#00ffffff'>
<img w='40' h='40' radius='20' src='appicon.png'/>
</frame>
";
var manager = runtime.FloatyHelper.CreateFloatyManager();
var view = manager.ParseXml(xml);
floatyWindow = manager.CreateSystemFloaty(view);
floatyWindow.Show();
}
}));
runtime.Ui["remove"].On("click", new OnClickListener((v) =>
{
floatyWindow?.Remove();
floatyWindow = null;
}));
runtime.Ui["setPosition"].On("click", new OnClickListener((v) =>
{
if (floatyWindow is not null)
{
var x = new Random().Next(390);
var y = new Random().Next(690);
floatyWindow?.SetPosition(x, y);
}
}));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。