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
0
votes
1 answer

How to set a Custom View (not an image) at the end of a multiline TextView in Android?

I am trying to add a custom view (the portion with red boundary will be replaced with my custom view having a 3 dots loader animation) at the end of a multi-line TextView in my Android app. I know how to specifically add an ImageView using a…
0
votes
1 answer

Multiple spannableString.setSpan in a loop

I'm creating a calculator app using Kotlin. I want to highlight the operation characters (+, -, *, /) by making their color blue. The array operationsInStrings is filled with indexes of characters from string that I wish to change the color to blue.…
0
votes
1 answer

Dynamically replace url's with custom text hyperlink url in Android TextView

Let’s say you have the string: "https://google.com to go to google. https://amazon.com to go to Amazon." In a TextView, how would you replace the url’s with a link that shows “Click here” (or “Haz clic aquí” in spanish) and would take you to the…
0
votes
1 answer

Android EditText, change color, styles while typing

I am making an android advanced editor that allow user to change text color, styles (bold, italic, underline) while typing. I'm able to achieve the styles by using SpannableStringBuilder, but seemlike SpannableStringBuilder can be applied to…
Huy.Vu
  • 173
  • 10
0
votes
2 answers

when I set ImageSpan and ellipsize I want see ...and ImageSpan all display

I have a TextView and I want to achieve this ellipse effect: Here is my XML layout:
0
votes
1 answer

SpannableStringBuilder setting String partially as bold not working

I'm using SpannableStringBuilder to set a string partially with a style of bold, however it's not working and I am unsure of what I am doing incorrectly. String normalText = "New Here? "; String boldText = "Register"; SpannableStringBuilder…
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
0
votes
1 answer

How does TextView's append() method call the replace() method of SpannableStringBuilder

I have this custom SpannableStringBuilder class: public class ExpressionBuilder extends SpannableStringBuilder{ public ExpressionBuilder(CharSequence text){ super(text); } @Override public SpannableStringBuilder…
Toni Joe
  • 7,715
  • 12
  • 50
  • 69
0
votes
0 answers

spannablestring not bolding text

I have the following function - private fun initData() { tasksViewmodel.getGroupsAndTasksCounter().observe(requireActivity(), Observer {model -> if (model.groupsCount == 0 && model.tasksCount == 0) { …
Alon Shlider
  • 1,187
  • 1
  • 16
  • 46
0
votes
1 answer

Android - Spannable: Unable to set multiple spans at once

I have the following code to set a color span on multiple subStrings of the same string. fun getColoredText(text: String, @ColorInt color: Int, vararg coloredSubText: String): Spannable { val spannable = SpannableString(text) for…
0
votes
0 answers

How to add customized spannable string with image to get this effect

I'm trying to get this effect. I have a textview and at my required places I need to add the span with image and border around it. With this How to set a rectangular-dashed/dotted-line-outline around partial text in TextView?, I able to draw the…
0
votes
1 answer

Android : How to espape a 'greater than sign' in Html.fromHtml() which is understood as start tag instead of greater than sign

I have a problem with Html.fromHtml which interprets "<" as a start tag and not as a "greater than" sign. Is there a way to escape the "<" sign so it is displayed ? Ex : Html.fromHtml("Test : 10", Html.FROM_HTML_MODE_LEGACY) Gives Test :…
Nathalie
  • 625
  • 6
  • 19
0
votes
2 answers

Using getSpans method to get all spans in a spannable

I use the following code to get all spans in a spannable string. SpannableStringBuilder str = new SpannableStringBuilder(editText.getText()); Object [] objectSpans = str.getSpans(0, str.length(), Object.class); //loop through all spans for (Object…
0
votes
1 answer

SpannableStringBuilder not displaying text in Text View

I'm trying to make an array of strings individually clickable within a text view that is within a RecyclerView (each tag would pass different data, which is fetched from the api on load). I've created the string using SpannableStringBuilder as…
Jason
  • 209
  • 2
  • 13
0
votes
0 answers

Change text using SpannableStringBuilder

I want to make text when surrounded by (*) it will be bold and surrounded by (~) it will be strike. I following this link and modify the code to be like this text = "*~TEST~* *TEST* ~TEST~ TEST"; texview.setText(createSpannable(text)) private…
valentino
  • 216
  • 3
  • 8
0
votes
0 answers

Transparent character with solid underline (Attempting with two spannables but open to alternatives)

I'm trying to set a single character in my TextView to transparent but also underlining that character. The underline should be visible. Since I'm already using a SpannableStringBuilder I decided to try setting the foreground color for the…
Programmer001
  • 2,240
  • 2
  • 19
  • 35