Last active
July 23, 2018 08:29
-
-
Save DanishAmjad12/8ac8c5ebe4463a7722df434b226d73a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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