Created
March 28, 2018 21:47
-
-
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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