hexagod
hexagod

Reputation: 469

Xamarin.Android: How to Get an Icon

I'm trying to get an Android.Graphics.Drawables.Icon but unsure of how to do so.

I've got this code:

Icon icon = Resources.GetDrawable(Resource.Drawable.tab_subs);

I'm not able to do this, because of exception:

Cannot implicitly convert type Android.Graphics.Drawables.Drawable to Android.Graphics.Drawables.Icon

I've tried casting into an Icon, no dice:

Android.Graphics.Drawables.Icon icon = (Icon)Resources.GetDrawable(Resource.Drawable.tab_subs);

To make matters worse, Resources.GetDrawable(int) is obsolete: 'deprecated'

...and resource tab_subs is available in other contexts. For some reason, the resource is not available in the context of MainActivity

https://github.com/hexag0d/BitChute_Mobile_Android_BottomNav/blob/AppSettingsAdder/MainActivity.cs

Does anyone know how to get an Icon in xamarin.android ?

Here is the Resource file:

https://github.com/hexag0d/BitChute_Mobile_Android_BottomNav/blob/AppSettingsAdder/Resources/drawable/tab_subs.png

Upvotes: 1

Views: 1182

Answers (1)

Robert Bruce
Robert Bruce

Reputation: 1088

Maybe this is what you're after?

Icon icon = Icon.CreateWithResource(this, Resource.Drawable.tab_subs);

More information and other ways to load an Icon are documented here... https://developer.android.com/reference/android/graphics/drawable/Icon#public-methods_1

Upvotes: 1

Related Questions