在代码中添加如下方法:
private void updateWallpaperVisibility(boolean visible) {
int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
int curflags = getWindow().getAttributes().flags
& WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
if (wpflags != curflags) {
getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
}
}
public static boolean forceOpaqueBackground(Context context) {
return WallpaperManager.getInstance(context).getWallpaperInfo() != null;
}
在Activity的onStart()中添上如下代码:
// Hide wallpaper if it's not a static image
if (forceOpaqueBackground(this)) {
updateWallpaperVisibility(false);
} else {
updateWallpaperVisibility(true);
}
将Activity的theme设置为
android:theme="@android:style/Theme.Translucent"