Skip to content

Instantly share code, notes, and snippets.

@CarlosACepeda
Created March 28, 2018 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosACepeda/8bad4ba91071d6aa2008f58460337f83 to your computer and use it in GitHub Desktop.
Save CarlosACepeda/8bad4ba91071d6aa2008f58460337f83 to your computer and use it in GitHub Desktop.
This is a snippet in how to Convert <Android.Graphics.Drawables.Icon> to <Android.Graphics.Drawables.Drawable> [c#] [Android][Xamarin.Android]
//Static: No need to make an instance to call this method.
// Receives two arguments:
//Icon: the Icon to convert:
//Paquete: Package of the app where the icon resides, needed to retrieve an icon from another application.
public static Drawable ReturnActionIconDrawable(Icon icon, string paquete)
{
//New Context field.
Context remotePackageContext = null;
//Create a context using the package passed in <paquete>
remotePackageContext = Application.Context.CreatePackageContext(paquete, 0);
//Using Icon#LoadDrawable(<Context>)
return icon.LoadDrawable(remotePackageContext);
}
//If is for retrieving Icons from our Own app you can just:
public static Drawable ReturnActionIconDrawable(Icon icon)
{
return icon.LoadDrawable(Application.Context); <-- Xamarin.Android.
return icon.loadDrawable(getApplicationContext()); <--Java
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment