Skip to content

Instantly share code, notes, and snippets.

@wcoder
Created June 9, 2021 21:45
Show Gist options
  • Save wcoder/0716dd03af3d72c21424b73973b7364c to your computer and use it in GitHub Desktop.
Save wcoder/0716dd03af3d72c21424b73973b7364c to your computer and use it in GitHub Desktop.
private void SetLeftDrawableWithBounds(Button button, int drawableResId, Size size, Android.Graphics.Color tintColor) {
var context = button.Context;
var drawable = DrawableCompat.Wrap(AppCompatDrawableManager.Get().GetDrawable(context, drawableResId)).Mutate();
drawable.SetBounds(0, 0, (int) context.ToPixels(size.Width), (int) context.ToPixels(size.Height));
if (tintColor != Android.Graphics.Color.Transparent) {
DrawableCompat.SetTint(drawable, tintColor);
}
button.SetCompoundDrawables(drawable, null, null, null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment