Multiple Resource Folder In Android

Multiple Resource Folders In Android

You can manage your resources XML files (layout, drawable,..) better, by grouping them into separate subfolders corresponding to app’s features.

Step to Create Multiple Resource Folders in Android

  • Create a parent folder that contains all layouts of our project.
  • Create The Features Folder.
  • Adding Resource Folder For The Features.
  • Android Resource Folders Into Android Resources.
  • Adding / Accessing Resource Files.

Step 1 – Create a parent folder that contains all layouts of our project.

Switch project tree explorer to Project view.

android project view
Switching To Project View

Right click in res,select New → Directory, name it as layouts.

naming the resource folder as layouts
Naming the resource folder as layouts

Step 2 – Create The Features Folder

Select layouts folder you created, Then right click and select New → Folder → Res Folder.

Creating new Res Folder for the Resources. New -> Folder -> Res Folder
Create New Res Folder For The Feature

Name the folder based on your feature. In my case, I have named as user, details.

Create Resource folders under the layouts folder for all your features.
Naming the resource folder by feature

Related Post

Support multi-language in Android

View images from folder in android

Step 3 – Adding Resource Folder For The Features

Then, Create resource folders like layout, drawable, menu,anim,etc for the created feature folders. In my example, I have created layout and drawable resource folders.

Adding Resources folders like layout , drawable under the feature folder
Resource Folder For The Features

Step 4 – Android Resource Folders Into Android Resources

Dmytro Danylyk (A Google Developers Experts) says, That we can have multiple res folders within by add resource sets.

Add the below lines of code into your app’s build.gradle file inside android tag.Then,  re-sync Gradle and rebuild the project. 

android {
    sourceSets {
        main {
            res.srcDirs = [

Step 5 – Adding / Accessing Resource Files

Then, you can add your layout, drawable resources directly into respecting feature folder. Then, To Access the resources you can use standard way of calling like R.layout.activity_user.xml ,

adding the layout, drawable resources into respective folders.
Adding Resources To Features Folder
Accessing Resource From Activity

In Conclusion

I believe, It will help you to manage your android project resource better. Thanks for the reading.

Leave a Reply

Your email address will not be published. Required fields are marked *