Eric Eric - 1 month ago 14
Android Question

I can't get Id of some image resource in Xamarin Project?

I am trying to get Id of image resource in drawable folder.
enter image description here

Here is my code.

...
int resourceId = Context.Resources.GetIdentifier("Elements_ok", "drawable", this.context.PackageName);


I always got the result of Zero.
But I got Id of image named error.png.

int resourceId = Context.Resources.GetIdentifier("error", "drawable", this.context.PackageName);


Is there a way that I can fix it?

Answer

Yep, just change your drawable filenames to lowercase.

And, of course, update any code that uses those filenames accordingly to use lowercase strings.

Since Android only supports lowercase filenames for resource items, I would also recommend updating all your drawable resource filenames to lowercase to eliminate any other potential issues.

Comments