Android Transparent Wallpaper

1. Create new theme in style.xml

<style name="Transparent.Them" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:colorPrimaryDark">@android:color/transparent</item>
</style>

2. Set the theme in manifest file

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Transparent.Them">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

3. Add background of parent tag in main layout

android:background="#00000000"
First two digits represent the alpha value 
the greater the value the less transparency.

4. Add a viewpager in layout xml file

<androidx.viewpager.widget.ViewPager
    android:id="@+id/vpager"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:layout_centerInParent="true">

</androidx.viewpager.widget.ViewPager>

5. In java file

ViewPager viewPager;
viewPager = findViewById(R.id.vpager);
viewPager.setAdapter(new ViewPagerAdapter(this,imgUrl));

6. Create a new class ViewPagerAdapter

public class ViewPagerAdapter extends PagerAdapter{
Context context;
String[] imgUrl;
LayoutInflater inflater;

public ViewPagerAdapter(Context mcontext, String[] imgurl){
      this.context = mcontext;
      this.imgUrl = imgurl;
      inflater = LayoutInflater.from(context);
   
}
@Override
public int getCount() {
    return imgUrl.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
View view = inflater.inflate(R.layout.img_layout,container,false);
ImageView imageView = view.findViewById(R.id.imgv);

Picasso.get()
.load(imgUrl[position])
.into(imageView);

container.addView(imageView);
return view;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
}

7. Now add the image url in array

String[] imgUrl = {
“https://fsb.zobj.net/crop.php?r=7TaarmTBWNoz3Ni3q_4RHmMokv4vvtevmhHZQfJetm3T4sbY0w7Sw8_2BFe8Hl70MPK8aCooRUZSRJwQF5ifpGhX2HFO5WQbwSneGKNo_KA4rS1e-fqgMnlfVon_X6SBeS045OZy1glXrXED”,
“https://fsa.zobj.net/crop.php?r=O5XDFCO5g2mTYJjL4Dsb8Hnl6n_SUHe-Mhr04MtBbW8Odnl_rSddiLU2yMB2z-X8zqnzpuWN-KCDrORRn_v4VM30w4SDBbvTx2VvSIIhLG5wfhfmNFngcCNoyKZvNsTNgszBo8IZR3-OIknA”,
“https://fsa.zobj.net/crop.php?r=mSwaFN6BST0BW5uhEQNJBBMyETyuDz_Gwd_61XsATro59t21YOomy_eDmqb8BXvdWSP6-g4rfSR3sb3m_ONtNEPLYFguxuBXJU3o9fJwe9vnDm6O8M95LYaWfJhndWaE22l8jhtVy3YVY_Xt”,
“https://mobilehd.blob.core.windows.net/main/2017/02/girl-sexy-black-swimsuit-look-1080×1920.jpg”,
“https://mobilehd.blob.core.windows.net/main/2018/11/ratajkowski-emily-model-girl-lingerie-violet-sexy-pretty-wall.jpg”,
“https://mobilehd.blob.core.windows.net/main/2018/11/sexy-woman-nude-fashion-lingerie-girl-erotic-model-glamour-portrait-monochrome-skin.jpg”,
“https://c4.wallpaperflare.com/wallpaper/74/899/631/eva-green-sexy-wallpaper-preview.jpg”,
“https://c4.wallpaperflare.com/wallpaper/1012/636/935/sexy-girl-image-2880×1800-wallpaper-preview.jpg”,
“https://c4.wallpaperflare.com/wallpaper/252/207/781/sensuality-sensual-sexy-woman-girl-shorts-evelyn-sharma-legs-belly-tummy-top-wallpaper-preview.jpg”,
“https://c4.wallpaperflare.com/wallpaper/335/207/603/girl-blonde-model-room-wallpaper-preview.jpg”,
};

8. Main layout xml file

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#00000000"
android:padding="10dp">

<androidx.viewpager.widget.ViewPager
android:id="@+id/vpager"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_centerInParent="true">

</androidx.viewpager.widget.ViewPager>

<Button
android:id="@+id/btnset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/vpager"
android:text="set"
android:onClick="SetWall"/>

</RelativeLayout>

9. Now on button click

On button Click call the method for changing the wallpaper.

This will require the Glide library.

 1. Add the dependency

       implementation‘com.github.bumptech.glide:glide:4.11.0’

2. Get the current image position by 

     int pos = viewPager.getCurrentItem();

3. Now add the following code 

Glide.with(MainActivity.this)
.asBitmap()
.load(imgUrl[pos])
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
try{
WallpaperManager.getInstance(MainActivity.this).setBitmap(resource);

}catch (Exception e){}
}
});

 

10. Manifest Permission

Add the internet permission and the SetWallpaper permission

<uses-permission android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.SET_WALLPAPER”/>

11. Create a separate image xml layout

<ImageView
android:id=”@+id/imgv”
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

</ImageView>

Leave a Comment