gpt4 book ai didi

java - Android:将墙纸更改为可绘制

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:19 24 4
gpt4 key购买 nike

我正在使用这段代码来更改 android 主页的墙纸

WallpaperManager wm = WallpaperManager.getInstance(this);
wm.setBitmap(myBitmap);

我想将背景设置为可绘制对象。这可能吗?

最佳答案

您首先必须将 Drawable 转换为位图。如何做到这一点我找到了here .您需要使用 BitmapFactory 类,特别是 decodeResource() 方法。

只需传入资源和资源 ID 作为参数,如下所示:

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.my_drawable);
wm.setBitmap(bmp);

关于java - Android:将墙纸更改为可绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3992086/

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