预览模式下的动态壁纸
我需要我的壁纸在预览模式下(屏幕上有“设置”和“设置..”)时有不同的行为。我怎么知道它什么时候被绘制在那里?
I need my wallpaper to act differently when in preview mode (the screen with "Settings" and "Set .. "). How do i know when it's drawn there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
onCreateEngine()
中,您可以使用isPreview()
方法。请注意,
onCreateEngine()
“通常”会调用两次:一次是为了创建预览实例,另一次是在您实际设置壁纸时调用。详细信息请参见:http://developer.android.com/reference/ android/service/wallpaper/WallpaperService.Engine.html
Within
onCreateEngine()
you can use theisPreview()
method.Note that
onCreateEngine()
is "normally" called twice: once to create an instance for preview, and then again when you actually set the wallpaper.Details here: http://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine.html
isPreview()
方法可以在已实现的 Engine 的onCreate(SurfaceHolderholder)
方法中调用。不在onCreateEngine
方法中作为先前的答案,因为该方法尚未准备好。The
isPreview()
method can be called in theonCreate(SurfaceHolder holder)
method of the implemented Engine. Not in theonCreateEngine
method as the prior answer because the method is not ready.除了代表的答案之外,我还会写。
由于预览和非预览引擎实例可以同时存在,您可以在您的 WallpaperService 类中添加引擎的两个静态实例和一个局部变量(Kotlin 中的示例):
并在重写函数中使用它们
这样您就可以始终获取当前您的壁纸服务中的引擎实例并调用其isPreview。
I'll write in addition to represented answers.
As the preview and non-preview engine instances could exist simultaneously, you can add two static instances and one local variable of your engine inside your WallpaperService class (sample in Kotlin):
and use them in overriding functions
This way you can always get the current engine instance in your WallpaperService and call its isPreview.