我正在尝试将我在Android上找到的Java示例转换为C#:
[Service]
public class SampleService :Service
{
public override IBinder OnBind(Intent intent)
{
return null;
}
public override void OnCreate()
{
base.OnCreate();
// create a windowManager object - relatively easy
var windowManager = GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
// create layoutParams based on WindowManager LayoutParams class
// (i.e. static member of class that doesn't exist in service context?!?!
var layoutParams = new WindowManager.LayoutParams(1, 1,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
}
}
问题是在C#世界中,WindowManager
似乎在服务中不可用,而在Java中它是(至少根据我看到的例子)。
在C#中,IWindowManager
可用,但不包含静态成员。
有办法做到这一点吗?
似乎不是使用WindowManager
,而是使用该类
WindowManagerLayoutParams
所以代码:
LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
变
var layoutParams = new WindowManagerLayoutParams(1, 1,
WindowManagerTypes.SystemOverlay,
WindowManagerFlags.WatchOutsideTouch,
Format.Translucent);