gpt4 book ai didi

java - 当 Activity 背景设置为系统壁纸时,如何更新 Activity 背景?

转载 作者:行者123 更新时间:2023-12-01 11:46:43 27 4
gpt4 key购买 nike

我有这段代码,它允许我将当前设备壁纸设置为我的 Activity 背景。

public void wallpaperBackground()
{
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();

View root = findViewById(R.id.home_view);
root.setBackground(wallpaperDrawable);
}

问题是,如果我通过设置更改壁纸,它不会在我的应用程序上更新,并且我会保留之前的壁纸。我该如何解决这个问题?

最佳答案

实际上很简单:

只需在 Activity 的 onResume() 中调用 wallpaperBackground() 方法即可。

当用户从另一个应用返回后 Activity 恢复时,这将自动应用正确的壁纸。

关于java - 当 Activity 背景设置为系统壁纸时,如何更新 Activity 背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29084245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com