这是示例代码:

        WallpaperManager wallpaperManager1 = WallpaperManager
                .getInstance(getApplicationContext());

        final Drawable wallpaperDrawable1 = wallpaperManager1.getDrawable();
        getWindow().setBackgroundDrawable(wallpaperDrawable1);

        if (wallpaperDrawable1==null)
        {
            Resources res = getResources();
            Drawable drawable1=res.getDrawable(R.drawable.bg1);
            getWindow().setBackgroundDrawable(drawable1);

        }


我想在我的应用程序中获取系统背景,如果该背景不存在或用户将其删除,那么我想从我的应用程序中设置默认图像以设置为应用程序背景。希望一切都清楚...

最佳答案

要查看当前系统是否具有墙纸,请使用peekDrawable()

final Drawable wallpaperDrawable1 = wallpaperManager1.peekDrawable();


另外,您错过了else

if (wallpaperDrawable1==null)
{
    Resources res = getResources();
    Drawable drawable1=res.getDrawable(R.drawable.bg1);
    getWindow().setBackgroundDrawable(drawable1);

}
else
{
    getWindow().setBackgroundDrawable(wallpaperDrawable1);
}

关于java - 更改应用程序的背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8600888/

10-12 00:37