我想把家里的墙纸套装起来,把它作为我活动的背景。这是可能的吗?
我在网上搜索了一下
WallpaperInfo v = w.getWallpaperInfo();
String name = v.getServiceName();
我有服务名称(因为墙纸是实时服务),例如,我有com.android.wallpaper.grass.GrassWallpaper
...can,我可以使用它在我的活动中启动服务?
如果是这样的话,是怎么做的?
发布于 2012-05-25 16:03:49
尝试将此属性添加到清单中的标记中:
android:theme="@android:style/Theme.Wallpaper“
发布于 2011-02-13 07:41:58
看起来你甚至都没试过做任何事。无论如何,您可以通过执行以下操作来获得墙纸:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
然后,您可以使用该可绘制并将其设置为活动的背景。
发布于 2020-10-24 08:14:23
使用WalpaperManager
需要storage permition
。所以我推荐这个神奇的方法:
如果你的主题名是AppTheme
,应该是这样的:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然后创建另一个名为AppTheme.Wallpaper
的主题
<style name="AppTheme.Wallpaper" parent="AppTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowShowWallpaper">true</item>
</style>
然后将该主题作为您的活动属性放入清单中:
<activity android:name=".YOUR_ACTIVITY"
android:theme="@style/AppTheme.Wallpaper">
</activity>
https://stackoverflow.com/questions/4981367
复制相似问题