1

我有一个 1.6 版的 Android 应用程序,我将壁纸显示在我的应用程序上。(我通过在 Activity 上调用 getWallpaper() 以编程方式执行此操作)

当它安装在具有动态壁纸的 2.1 手机上时,getWallpaper() 不会返回动态壁纸,因为它只返回一个 Drawable,而动态壁纸可能是另一回事。

那么问题来了,是否可以在 1.6 应用程序的背景上显示动态壁纸?如何?

谢谢

==================================================== =======================================

到目前为止,我还没有找到解决方案。我添加这个是为了更好地理解这个问题

需要明确的是:该应用程序是为 1.6 编写的,因此它可以在所有 1.6 及更高版本上运行。问题是:我们是否可以编写一个以 1.6 为目标的应用程序,但如果它在 2.1 设备上运行,则支持动态壁纸?

谢谢

4

3 回答 3

2

我找到了一个解决方案:

1) 使用 android.os.Build.VERSION.SDK_INT 检查手机的版本。2) 进行 if/else 调用,因此对于每个版本,您都可以调用所需的方法。在这种情况下:

如果(android.os.Build.VERSION.SDK_INT >= 7){

this.setTheme(android.R.style.Theme_Wallpaper);

}

别的

{

//其他的

}

3) 使用 2.1 构建应用程序。并在清单中设置 uses-sdk android:minSdkVersion="4" 所以它也可以在 1.6 上运行

4) 确保它在手机 1.6 和 2.1 上都可以工作,因为因为你调用了这两个 SDK,所以当你运行 1.6 时,请确保不要调用 2.1 的方法,反之亦然。

谢谢您的帮助

于 2010-04-09T14:21:03.900 回答
1

Live wallpapers were added in 2.1, so it simply does not make sense to try to show a live wallpaper on a 1.6 (or 2.0) device.

In 2.0 the Theme.Wallpaper theme style was added, which as the new official way to put an activity (or window) on top of the system's wallpaper (live or not). Of course, since this appeared in 2.0, you also can not use this in 1.6.

Prior to 2.0, the only way to display on top of the system wallpaper was to use getWallpaper() to retrieve the static wallpaper image, and take care of drawing it yourself in your UI. This of course can not support live wallpapers.

If you want to have an app that shows in the wallpaper on both pre-2.0 and 2.0 and later versions of the platform, you will need to check the API version in android.os.Build, and adjust your behavior appropriately: when initializing your activity, if 2.0 or later use setTheme to choose the wallpaper theme; otherwise, get the drawable and make it the background of your UI. When using the wallpaper theme, you need to make sure your UI does not draw an opaque background on top of it and cover it up. You may also want to try setting your activity's theme to Theme.Translucent, to get better behavior on 2.0 or later (where ideally you would use Theme.Wallpaper which also gives you the proper animations).

Actually, you could conceivable use versioned resouurces to make your own theme that adjusts appropriately depending on the platform version (either a wallpaper or a traditional theme). I have never tried to do this, though.

于 2010-03-26T19:39:35.370 回答
0

您是否尝试过Theme.Wallpaper用作 Activity 的主题?这会将手机的壁纸设置为活动的背景,并与动态壁纸一起使用。

于 2010-03-26T16:06:08.247 回答