neworld / spanner

Simple and fluent spannable builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vector image not being showned

jrcacd opened this issue · comments

commented

Kotlin:

val texto = Spanner()
texto.append("", image(context.getResources().getDrawable(R.drawable.ic_star_on)))

Am I doing something wrong?

You are applying drawable on "" A.K.A nothing. It should be at least " " (space). The same, as if you are using SpannableStringBuilder. I will think what could be done here. Maybe, do you have any idea?

Added less ambiguity method for appending images. Should following code work:

Spanner().append(image(context.getResources().getDrawable(R.drawable.ic_star_on)))

This feature released with 0.4.0

commented

Still doesn't show the image.

val spanner = Spanner()
spanner.append(image(context.getResources().getDrawable(R.drawable.ic_star_on)))
title.text = spanner  //TextView

I will check vector case.

I spent some time to investigate until I realized probably bounds of the image are wrong. This library is a simple wrapper for SpannableStringBuilder and inherits all weakness from it. Working solution is in the sample. I am not sure, this lib should change bounds because sometimes you want use specified size. Since you are using kotlin, you could write extension functions which helps to you.

I added another span creator. Following code should work:

val texto = Spanner()
texto.append(image(context, R.drawable.ic_star_on))

If you are supporting older than 21, you may need to enable vector support from resources:

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
commented

It's working. Thanks,

commented

A question: How do I set the image tint?

You should use old solution but define bounds. I could create something like imageIntrinsicBounds(). What do you think?