问题描述
我正在尝试引用 WindowManger 以便我可以获得默认屏幕的尺寸,但我似乎找不到对它的引用.(这是 API 8,froyo 2.2).我什至尝试过:
I'm trying to reference WindowManger so I can get the default screen's dimensions but I can't seem to find reference to it. (this is API 8, froyo 2.2). I even tried:
dynamic wm = Android.App.Application.Context.GetSystemService(Android.Content.Context.WindowService);
Display display = wm.getDefaultDisplay();
但是得到一个错误,指出 Object
没有响应 getDefaultDisplay
.
But got an error indicating that Object
doesn't respond to getDefaultDisplay
.
我也试过:
var wm = (IWindowManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.WindowService);
Display display = wm.DefaultDisplay;
但我收到了无效的强制转换异常.
But I get an invalid cast exception.
看到这篇文章,但我无法解决.知道这里发生了什么吗?
Saw this post, but I can't resolve WindowManager
. Any ideas what's going on here?
推荐答案
WindowManager
是 IWindowManager 接口.尝试使用 .JavaCast<T 而不是演员表>() 扩展方法:
WindowManager
is the IWindowManager interface. Instead of the cast, try using the .JavaCast<T>() extension method:
var wm = context.GetSystemService(Android.Content.Context.WindowService)
.JavaCast<IWindowManager>();
var d = wm.DefaultDisplay;
您还可以查看 AccelerometerPlay 示例.
这篇关于Monodroid 屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!