0

I found that back in 2009, it was impossible to insert sub-directories for the Drawable folder (Can the Android drawable directory contain subdirectories?).

Since it has been more than ten years from then, I wonder if Android Studio ever updated a way to insert sub-directories to group images together. I added more than 80 images in the Drawable folder, and it's pretty bugging me... Thanks!

1 Answers1

3

No, the Android resources mechanism doesn't support any custom directory or subdirectory yet (instead of the assets for example).

However, you can implement a structure similar to:

|--- res
|
|--- circles
|       |--- drawable
|               |--- my-circle.xml
|
|--- triangles
|       |--- drawable
|               |--- my-triangle.xml
|
|--- selectors
        |--- drawable
                |--- my-selector.xml

And with Gradle you can add src/main/circles, src/main/triangles and src/main/selectors to your res directories.

e.g.

android {
    sourceSets {
        main.res.srcDirs += ['src/main/circles', 'src/main/triangles', 'src/main/selectors']
    }
}

Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70
  • Thank you for your helpful reply! You saved my thousands of scrolling to find the exact name of a file name. –  Mar 21 '20 at 22:38
  • 1
    Antoniolli Just did! I am new to here and didn't know about the feature. Thanks again! –  Mar 21 '20 at 22:51
  • 1
    Note that you can't have two files with same filename, even if they are in distinct subdirectories. – dankal444 Oct 17 '22 at 14:22