1

Can I check the type of drawable at runtime whether it is an xml shape/selector/layer-list or jpg/png/gif file?

User
  • 4,023
  • 4
  • 37
  • 63
  • http://stackoverflow.com/questions/13760269/android-how-to-check-if-file-is-image – Amit Vaghela Sep 09 '16 at 10:49
  • 1
    Khan U can set there ids explicitly as tag and then get them when u needed that for example chk this link http://simplyadvanced.net/blog/android-how-to-get-the-drawable-id-for-imageviews/ – Adeel Turk Sep 09 '16 at 10:54

1 Answers1

1

You can get type of drawable with this:

public static String getTypeOfDrawable(int drawableId,Context context) {
    Drawable resImg = context.getResources().getDrawable(drawableId);
    return resImg.getClass().toString().replace("class android.graphics.drawable.","");
}

You will get result like:

BitmapDrawable

StateListDrawable

Then you if it is BitmapDrawable its not that hard to get format of file

Community
  • 1
  • 1
Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56