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.
Created attachment 1783 [details]
error icon drawable
The function to set the error for an EditText field that shows the fly over indication and a red error icon is not working as expected in the Mono for Android sdk.
There is no function that only takes an error string (and uses the standard Android error icon) and when i give along a drawable to use as icon in the EditText field it won't show:
The errorMessage is shown allright, but the drawable error_icon (see attachment) won't show up.
I really want to show the icon since it is a clear indicator for the user that something is (still) wrong in one or more edittext fields.
This is kinda confusing, because the overload that only takes a string got changed into a property, so if you want to use the default Android icon, do this:
element.Error = errorMessage;
or if you have a formatted string:
element.ErrorFormatted = errorMessage;
Still need to look into why SetError (string, Drawable) isn't working as expected, but maybe this will let you work around that.
I was getting around using a custom icom using
element.SetError(errorMessage, null); // passing an icon ref here doesn't work element.SetCompoundDrawablesWithIntrinsicBounds(0,0,Resource.Drawable.error_icon,0);
but i just confirmed that using .Error works (nice!) and shows the - more crisp - default icon.
it's just a tad more confusing since all the Android examples use setError and there is no single parameter overload. Is making one-parameter functions properties common practice for mono for android? if so, i think i'll be able to switch a little faster next time ;)
While I couldn't find out the reason why it doesn't work yet, I found a workaround that gets SetError(string,Drawable) as expected: use dummy ImageView and hold the drawable in it, like:
icon = Resources.GetDrawable (Resource.Drawable.error_icon);
var iv = new ImageView (this); // dummy
this.AddContentView (iv, new ViewGroup.LayoutParams (0, 0)); // dummy
iv.Visibility = ViewStates.Invisible;
var ed = FindViewById<EditText> (Resource.Id.myEdit);
ed.SetError ("error by default", icon);
I assume this is some native resource preservation issue.
It is due to wrong use of API. The documentation explicitly says:
"The drawable must already have had setBounds(Rect) set on it."
If you add call to SetBounds(), it expectedly shows the icon. The workaround code above must be internally doing that too.