Get home wallpaper and set it to my activity
I want to get the home wallpaper set and put it as my background for my activity. Is this possible ?
I searched on the internet with
WallpaperInfo v = w.getWallpaperInfo();
String name = v.getServiceName();
I have the service name (because the wallpaper is a live service) for example, I have com.android.wallpaper.grass.GrassWallpaper
...can I use this to 开发者_JS百科start service into my activity?
If so, how?
Try to add this attribute to your tag in the manifest:
android:theme="@android:style/Theme.Wallpaper"
It seems you even haven't tried to do anything... whatever, you can get the wallpaper by doing:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
Then, you can use that drawable and set it as the background of your activity.
using WalpaperManager
requires storage permition
. so I suggest this amazing way:
if your main theme name is AppTheme
, some thing like this:
<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>
then create another theme named 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>
then put that theme in the manifest as your activity attribute:
<activity android:name=".YOUR_ACTIVITY"
android:theme="@style/AppTheme.Wallpaper">
</activity>
精彩评论