![]() |
VOOZH | about |
Almost all Android devices are having a wallpaper set on their home screen. For setting this wallpaper to the screen many Android devices provides a Wallpaper Application where we can browse different types of wallpapers based on various categories. In this article we will look at, building a similar application in Android devices in Android Studio.
We will be building a simple wallpaper application in which we will be adding functionality to filter wallpapers based on various categories. Along with that we will be also adding a search bar to search wallpapers based on the user search query. Below is the video in which we will get to see what we are going to build in this article. Note that we are going to implement this project using the Java language.
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Before going to the coding section first you have to do some pre-task
Go to the app > res > values > colors.xml section and set the colors for your app.
Step 3: Adding dependency in build.gradle file
Go to the Gradle Scripts > build.gradle (Module: app) section and import the following dependencies and click the “sync Now” on the above pop-up.
implementation 'com.github.bumptech.glide:glide:4.11.0' implementation 'com.android.volley:volley:1.1.1' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' implementation 'com.github.Shashank02051997:FancyToast-Android:0.1.8'
Navigate to the app > Gradle Scripts > build.gradle(Project level) and in this file, we have to go to add mavenCentral in allProjects section.
allprojects {
repositories {
google()
mavenCentral()
// add below line
maven { url "https://jitpack.io/" }
jcenter()
}
}
After adding this dependency we simply have to sync our project to install the packages of all dependencies.
Step 4: Adding Internet Permissions in the AndroidManifest.xml file
Navigate to the app > AndroidManifest.xml file and add the below line of code in it.
Step 5: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Step 6: Creating a new Java Modal Class for storing the data of categories
Navigate to the app > java > your app's package name > Right-click on it > New > Java class and name it as CategoryRVModal add below code to it. Comments are added in the code to get to know in more detail.
Step 7: Creating drawable files
We will be creating two drawable files one will be for our button background. For creating this file, navigate to the app > res > drawable > Right-click on it > New and name it as button_back and add the code below. Comments are added in the code to get to know in more detail.
After that, we will be creating a drawable file for our search bar background. Similarly, create another drawable file and name it as search_back and add the below code to it.
Step 8: Creating a layout file for category_rv_item
Navigate to the app > res > layout > category_rv_item and add the below code to it. Comments are added in the code to get to know in more detail.
Step 9: Creating a layout file for the item in Wallpaper RecyclerView
Navigate to the app > res > layout > Right-click on it > New > Layout Resource file and name it as wallpaper_rv_item and add below code to it. Comments are added in the code to get to know in more detail.
Step 10: Creating an Adapter class for setting data to items of RecyclerView
Navigate to the app > java > your app's package name > Right-click on it > New > Java class and name it as WallpaperRVAdapter and add the below code to it. Comments are added in the code to get to know in more detail.
Step 11: Creating an Adapter class for our Category RecyclerView
Navigate to the app > java > your app's package name > Right-click on it > New > Java class and name it as CategoryRVAdapter and add the below code to it. Comments are added in the code to get to know in more detail.
Step 12: Creating a new Activity for displaying a single Wallpaper
Navigate to the app > java > your app's package name > Right-click on it > New > Activity > Select Empty Activity and name it as WallpaperActivity and now we will move towards working of activity_wallpaper.xml.
Step 13: Working with activity_wallpaper.xml file
Navigate to the app > res > layout > activity_wallpaper.xml and add the below code to it. Comments are added in the code to get to know in more detail.
Step 14: Working with the WallpaperActivity.java file
Navigate to the app > java > your app's package name > WallpaperActivity.java file and add the below code to it. Comments are added in the code to get to know in more detail.
Step 15: Generating the API key for Pixels API
For generating an API for using Pexels API we simply have to go to the Pexels site here. After going to this site we simply have to signup on this website and create an account. After creating a new account you have to simply login to your account. After logging in to your account. You will get to see the below screen.
👁 ImageIn this screen, we simply have to click on the account option arrow then simply select the Image and Video API option to get to see our API key. After clicking on that option a new screen will open in which we simply have to click on the Your API key option to get our API key. Then you will get to see your API which is shown below.
👁 ImageNow we will be using this API key in our application.
Step 16: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Now run your application and see the output of the application.
Note: All drawable files used in the app are present in the drawable folder. Check out the project on below GitHub link.
GitHub Link: https://github.com/ChaitanyaMunje/Wallpaper-App
Output: