Questions tagged [spannablestringbuilder]

Use this tag for questions related to the SpannableStringBuilder Android API class for text whose content and markup can both be changed.

The SpannableStringBuilder is an Android API class for text whose content and markup can both be changed. It is an excellent way to style strings in a TextView. It allows a TextView to provide different styles to different areas of text.

74 questions
1
vote
1 answer

SpannableStringBuilder only keeping formatting for the first for loop

I am trying to use a for loop to add formatting using SpannableStringBuild from strings in a list, however in the TextView, despite all the strings having been appended, only the string appended in the initial for loop keeps its formatting.
Tamzid
  • 47
  • 6
1
vote
1 answer

Efficiently applying text formatting on-the-fly by setting Spans onto EditText

I'm using an EditText control that I allow text formatting of (bold, italics etc.). To apply formatting, within my TextWatcher's AfterTextChanged event handler I detect whether a formatting style, such as bold, has been toggled on via the UI. If it…
1
vote
2 answers

How to move a word in an android textview above the next word using text span?

I'm trying to move a word above the next word in an android textview like in the attached image (example image). I have managed to shift the word upwards (like a superscript) with spannablestringbuilder, but I can't find a way to shift the right…
Alex
  • 11
  • 3
1
vote
1 answer

SpannableStringBuilder.insert() does not insert span if span of that type already present in the destination

I have 2 SpannableStringBuilders, sbDest and sbSrc. I want to insert sbSrc into sbDest: sbDest.insert(0, sbSrc) That works - and sbDest ends up with the spans it had before the insertion plus the ones that are present in sbSrc. However, if sbSrc…
DaveBound
  • 215
  • 4
  • 11
1
vote
1 answer

Kotlin - Create custom ext function for SpannableStringBuilder without duplicate arguments when declaring start, end & flasg for setSpans()

this is MainActivity.kt before var spannable = SpannableStringBuilder("$noColorText$coloredText") spannable.setSpan( ForegroundColorSpan(ContextCompat.getColor(textView.context, R.color.mainGreen)), noColorText.length, spannable.length, …
1
vote
1 answer

Can multiple setSpan be applied to the same SpannableStringBuilder?

I have a list of specific words from a sentence that I would like to bold and change the text color for. For some reason the text color change is working, but the bold does not seem to be applied. What's more weird is that changing the typeface to…
portfoliobuilder
  • 7,556
  • 14
  • 76
  • 136
1
vote
0 answers

Adding Onclick animation to spanned sections of spannablestringbuilder

I have successfully implemented the SpannableStringBuilder such that sections are colored differently and are click-able. However I need to include some onclick animation for a better user experience. How can I implement this. I have done a lot of…
1
vote
0 answers

CharSequence passed through intent arrives modified

I'm sending a CharSequence of a Spannable to another Activity via intent extras, but seem not to receive the same sequence. I'm doing that according to the following answer: https://stackoverflow.com/a/45638248/1545435 Here's the content of…
Ambran
  • 2,367
  • 4
  • 31
  • 46
1
vote
0 answers

Superscripting with SpannableStringBuilder

i'm making a math tool, and i've run into a bit of trouble with the graphical representation of it. I'm trying to superscript some strings, and the method i'm using is tV = (TextView) findViewById(R.id.textView); String textEAS; …
Dber
  • 21
  • 1
1
vote
1 answer

How quotes align-top with text in TextView?

I have a spannnable string and that spannable sting containg images and string and but When i Display that string on textview that images align with base line of textview i want to display ALIGN_TOP with that string I am stuck on this please help me…
1
vote
1 answer

How to get index of a character in spanned object?

i have this string String thestring="

Abcd® X (CSX) Open Cell

", I have used Html.from to skip the tags from printing like this: Spanned spst = Html.fromHtml(thestring); I also want the ® to be superscript, so i have used the following…
1
vote
1 answer

Android DataBinding/Recyclerview - set custom span for textview with SpannableBuilder

I'm migrating from old ListView to RecyclerView in my project. I have decided to use Data Binding to bind list values, but I'm experiencing some problems to set custom text span for my text box. Please look at this piece of code (this is how it's…
1
vote
1 answer

android - SpannableStringBuilder not working for mor than 2 phrase

I want to set multiple color on my textView and it has a lot of example on net, but it is not working for me :((( here is my code : public class MainActivity extends Activity { ImageView profile_picture; TextView ageTxt; Bitmap…
faeze saghafi
  • 650
  • 10
  • 25
0
votes
0 answers

Catch exactly which string was clicked in this textview witch was made by SpannableStringBuilder?

I have textview with SpannableStringBuilder. SpannableStringBuilder span = getSpanFromStringArray(); span.setSpan(new ImageSpan(bitmap), span.length() - text.length(), span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textview.setText(span); Haw…
Slava
  • 443
  • 4
  • 12
0
votes
1 answer

java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0, in AccessibilityNodeInfo.java at AccessibilityNodeInfo.replaceClickableSpan

Lately we've been experiencing a lot of crashes in our application due to IndexOutOfBoundsException being thrown by Android internally. Fatal Exception: java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0 at…
Vinay Rathod
  • 1,262
  • 1
  • 10
  • 19