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

Problem with Spannable #277

Closed
carmas123 opened this issue May 5, 2017 · 21 comments
Closed

Problem with Spannable #277

carmas123 opened this issue May 5, 2017 · 21 comments
Assignees
Labels

Comments

@carmas123
Copy link

carmas123 commented May 5, 2017

I try to use IconicsTextView with this:

val spannable = SpannableString("{gmi-pin} my text bla bla bla")
spannable.setSpan(ForegroundColorSpan(Color.MAGENTA), 0, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
mytextView.Text = spannable

but the Magenta Color does not appear.
If I change the TextView color for all text without spannable it work.

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@mikepenz mikepenz self-assigned this May 5, 2017
@carmas123
Copy link
Author

I try it but also does not work

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 can you please show what you tried? Because in the sample it is working fine

@carmas123
Copy link
Author

carmas123 commented May 5, 2017

Ok but I use Kotlin and not Java...

Iconics.IconicsBuilder().ctx(activity)
  .style(ForegroundColorSpan(Color.RED), BackgroundColorSpan(Color.RED), RelativeSizeSpan(2f))
  .styleFor("gmi-pin", BackgroundColorSpan(Color.RED), ForegroundColorSpan(Color.parseColor("#33000000")), RelativeSizeSpan(2f))
  .on(b.textView)
  .build()

The textview is always empty

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 shouldn't change much.

The textview is always empty? the code you posted will only adjust the color of the icon if it was set. So if no text is set, it makes sense that it stays empty :D

@carmas123
Copy link
Author

carmas123 commented May 5, 2017

myTextView.text = "{gmi-pin} my Text"
Iconics.IconicsBuilder().ctx(activity)
		.style(ForegroundColorSpan(Color.RED), BackgroundColorSpan(Color.RED), RelativeSizeSpan(2f))
		.styleFor("{gmi-pin}", BackgroundColorSpan(Color.RED), ForegroundColorSpan(Color.parseColor("#33000000")), RelativeSizeSpan(2f))
		.on(myTextView)
		.build()

This is the result

image

I try also with this:

myTextView.text = "{gmi-pin} my Text"
Iconics.IconicsBuilder().ctx(activity)
		.style(ForegroundColorSpan(Color.RED), BackgroundColorSpan(Color.RED), RelativeSizeSpan(2f))
		.styleFor("gmi-pin", BackgroundColorSpan(Color.RED), ForegroundColorSpan(Color.parseColor("#33000000")), RelativeSizeSpan(2f))
		.on(myTextView)
		.build()

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

Do you have any other spannables or fonts or so set manually? Anything which might break the icon?

any log output saying that the icon does not exist or so?

is it working without any color change or so?

@carmas123
Copy link
Author

Yes it work.without spannable

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

you mean without this:

val spannable = SpannableString("{gmi-pin} my text bla bla bla")

?

@carmas123
Copy link
Author

It work:

image

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 so why do you want this SpannableString then?

@carmas123
Copy link
Author

I need to highlight the Icon into TextView with another color

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 for this there is:

Iconics.IconicsBuilder().ctx(activity)
  .style(ForegroundColorSpan(Color.RED), BackgroundColorSpan(Color.RED), RelativeSizeSpan(2f))
  .styleFor("gmi-pin", BackgroundColorSpan(Color.RED), ForegroundColorSpan(Color.parseColor("#33000000")), RelativeSizeSpan(2f))
  .on(b.textView)
  .build()

and the best would anyways to set the Drawable as compound drawable

@carmas123
Copy link
Author

Yes but the text into TextView need to have {gmi-pin} or not?

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 if you set it as compound drawable not.

@carmas123
Copy link
Author

The result is same with this text:
b.textIndirizzo.text = "{gmi-pin} my text bla bla bla"
image

without {gmi-pin} is this:
image

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 and then you set the icon via the IconicsDrawable as compoundDrawable

@carmas123
Copy link
Author

mmm

@carmas123
Copy link
Author

It's work but with this I cannot use the com.mikepenz.iconics.view.IconicsTextView with all functionality :(

@mikepenz
Copy link
Owner

mikepenz commented May 5, 2017

@carmas123 well using the android iconics as Drawable via the IconicsDrawable is anyways the better and prefered solution. The other is just a gimmick, and gives by design (and by the limitations of Spannables) a less flexible and a more complicated solution...

@mikepenz mikepenz closed this as completed May 5, 2017
@tmm1
Copy link

tmm1 commented Jun 13, 2018

The other is just a gimmick, and gives by design (and by the limitations of Spannables) a less flexible and a more complicated solution...

I would suggest that this be mentioned in the README, as the gimicky solution is currently featured prominently and gives the impression that it is the recommended way to use the library. An example in the README of how to use setCompoundDrawables would be great too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants