JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 529 forks source link

Expose TextPaint in IconDrawable #199

Open dohamann opened 7 years ago

dohamann commented 7 years ago

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
    }