I have kind of a special use case to begin with. I want to use FontAwesome icons as markers on an OSMdroid map. This means I can't define a shadow for an icon in xml. However I can (and do) set a shadowlayer on the paint object inside the IconDrawable. The only downside so far is that I have to acquire the paint object by reflection.
My current code (written in kotlin)
fun markerIcon(context: Context, color: Int): Drawable {
val paintField = IconDrawable::class.java.getDeclaredField("paint")
val drawable = IconDrawable(context, FontAwesomeIcons.fa_map_marker)
.color(color)
.sizeDp(40)
paintField.isAccessible = true
val paint = paintField.get(drawable) as TextPaint
paint.setShadowLayer(5.0f, 0.0f, 0.0f, Color.BLACK)
return drawable
}
I have kind of a special use case to begin with. I want to use FontAwesome icons as markers on an OSMdroid map. This means I can't define a shadow for an icon in xml. However I can (and do) set a shadowlayer on the paint object inside the IconDrawable. The only downside so far is that I have to acquire the paint object by reflection.
My current code (written in kotlin)