Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Drawable.SetColorFilter method differs from the one in the native Android SDK
It wouldn't be a problem if there was a way to actually obtain a color from the resource as a Color object.
Currently, the workaround is:
Drawable.SetColorFilter takes an integer and PorterDuff.Mode
Drawable.SetColorFilter takes a Color and PorterDuff.Mode
Android Native SDK: https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setColorFilter(int, android.graphics.PorterDuff.Mode)
@jonp: is that intended?
@Atsushi: Yes, it's intended.
@Nikola: As much as possible (and backward compatibility limits this somewhat), we try to map Android's `int color` parameters/etc. to `Android.Graphics.Color color`. This is by design.
As per the Java documentation, the Java `int` parameter is a color:
> Specify a color and Porter-Duff mode to be the color filter for this drawable
As such, using Color as the parameter type is appropriate.
> It wouldn't be a problem if there was a way to actually obtain a
> color from the resource as a Color object.
Using Resources.GetColor(int) doesn't work?
Resources.GetColor(int) is deprecated as of Android Marshmallow 6.0 Using it in code will show us that. The better one to use is GetColor(int, Theme) which is not documented at all.
May I ask why is your design trying to replace integers with color objects?
> May I ask why is your design trying to replace integers with color objects?
They're not "objects", they're structs (value types), and the reason to replace color-related `int` types with Color is to make the API easier to use.
Rephrased, which would you prefer to read or write?
> They're not "objects", they're structs (value types), and the reason to replace color-related `int` types with Color is to make the API easier to use.
My bad. They are structs, not objects. But I do not see how mapping the original API to yours differently is making it easier to use. Why not have both then?
> Rephrased, which would you prefer to read or write?
I have no problem with both
> Why not have both
because, unlike method arguments, you cannot have two method overloads that only differ in the return value e.g.
int GetColorFilter(Mode mode)
Color GetColorFilter(Mode mode)