Skip to content

Instantly share code, notes, and snippets.

@DanishAmjad12
Last active July 23, 2018 08:29
Show Gist options
  • Save DanishAmjad12/8ac8c5ebe4463a7722df434b226d73a9 to your computer and use it in GitHub Desktop.
Save DanishAmjad12/8ac8c5ebe4463a7722df434b226d73a9 to your computer and use it in GitHub Desktop.
//region Helper method for PreLollipop TextView & Buttons Vector Images
public static Drawable setVectorForPreLollipop(int resourceId, Context activity) {
Drawable icon;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
icon = VectorDrawableCompat.create(activity.getResources(), resourceId, activity.getTheme());
} else {
icon = activity.getResources().getDrawable(resourceId, activity.getTheme());
}
return icon;
}
public static void setVectorForPreLollipop(TextView textView, int resourceId, Context activity, int position) {
Drawable icon;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
icon = VectorDrawableCompat.create(activity.getResources(), resourceId,
activity.getTheme());
} else {
icon = activity.getResources().getDrawable(resourceId, activity.getTheme());
}
switch (position) {
case ApplicationConstants.DRAWABLE_LEFT:
textView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null,
null);
break;
case ApplicationConstants.DRAWABLE_RIGHT:
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, icon,
null);
break;
case ApplicationConstants.DRAWABLE_TOP:
textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null,
null);
break;
case ApplicationConstants.DRAWABLE_BOTTOM:
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null,
icon);
break;
}
}
//endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment