设置当前Activity背景是当前使用的壁纸

来源:互联网 发布:23游戏数据平台 编辑:程序博客网 时间:2024/05/17 18:28

在代码中添加如下方法:

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"


0 0
原创粉丝点击