Nazerke
Nazerke

Reputation: 2098

Which drawable folder is being used?

I have 7 drawable folders with (7 qualifiers that is) all with the same named images, so I need to know how can I programmatically or otherwise find out which drawable folder the application is taking the images from: drawable-xhdpi, drawable-mdpi, etc?

Edit to question: There are precedence of qualifiers and situations where both drawable folders are possible candidates. For example drawable-large-mdpi and drawable-mdpi, or even the third candidate can be drawable-sw600dp if I have all three folders. I know there is a documentation on precedence of qualifiers, but I want to be sure on my conclusions

Upvotes: 3

Views: 2271

Answers (1)

Shahjahan Khan
Shahjahan Khan

Reputation: 189

try this code

switch (getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
    // handle your code here for ldpi
    break;
case DisplayMetrics.DENSITY_MEDIUM:
    // handle your code here for mdpi
    break;
case DisplayMetrics.DENSITY_HIGH:
   // handle your code here for hdpi
    break;
case DisplayMetrics.DENSITY_XHIGH:
    // handle your code here for xhdpi
    break;
}

Upvotes: 2

Related Questions