Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose TextPaint in IconDrawable #199

Open
dohamann opened this issue Jun 4, 2017 · 0 comments
Open

Expose TextPaint in IconDrawable #199

dohamann opened this issue Jun 4, 2017 · 0 comments

Comments

@dohamann
Copy link

dohamann commented Jun 4, 2017

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
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant