在动态壁纸中哪里可以使用 getWindowManager() ?
我收到错误“LiveWallpaperService 类型的方法 getWindowManager() 未定义”
由于我正在创建一个活动,因此无法引用它,我将如何在主类初始化之前获取屏幕宽度和高度在 onCreateEngine() 中,
它是首先被调用的。之前我使用背景图像来确定尺寸,但这对于不同的屏幕尺寸来说是很痛苦的。
有人可以帮我吗?我试过了:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
没有运气。
还尝试过:
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
我收到错误:“Activity无法解析为类型”
另外:
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
与:“WindowManager无法解析为类型”
无论我尝试什么,无论我在哪里放置此代码,我总是得到相同的错误,我尝试过使用
onSurfaceChanged
Int 的宽度和高度,但它们初始化得太晚,我的应用程序崩溃了,有人可以帮助我吗?谢谢?
I'm getting the error "The method getWindowManager() is undefined for the type LiveWallpaperService"
Since I'm creating an activity there is no way to reference that, how would I go around getting the screen width and height before the main class initialized within onCreateEngine()
It's the first thing that's called. Before I was using background image for dimensions but that's proving a pain with different screen sizes.
Can anyone please help me here? I've tried:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
With no luck.
Also tried:
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
I get the error: "Activity cannot be resolved to a type"
Also:
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
with : "WindowManager cannot be resolved to a type"
What ever I try, where ever I place this code I always get the same error, I tried using the
onSurfaceChanged
Int with width and height but they initialize too late and my application crashes, can anyone help my here thanks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)