Search code examples
androidandroid-drawable

is there any way to access drawable folder that I created besides default drawable folder in android studio?


I'm doing a project about entering mobile phones with country codes in android studio with kotlin jetpack compose. I think there are about 200 or 250 countries, and of course they have pictures. If I put these pictures in the drawable file, they can be mixed with other image files and a bad code will appear, I think. For this reason, I created a separate drawable file called drawable-country-flags and added the flag images to it, but when I say R.drawable.tr, I cannot access it and there is no other option. Can I access the flag images in this drawable file? if i can access how? Or is there a better way? can i get your suggestions?

I try to access this for example :

data class CountryData(
    private var cCodes: String,
    val countryPhoneCode: String = "+90",
    val cNames:String = "tr",
    val flagResID: Int = R.drawable.tr
) {
    val countryCode = cCodes.lowercase(Locale.getDefault())
}

enter image description here

enter image description here


Solution

  • No, you can't store your images here. You can only create drawable folders for different configurations (like screen sizes, night-light themes etc).

    I think you have 2 options to solve your problem:

    1. Name your images like country_flag_.... in order to faster navigate through your drawable folder
    2. Create separate module with resources and add it to your app's build.gradle as a dependency.