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
102
votes
11 answers

SpannableStringBuilder to create String with multiple fonts/text sizes etc Example?

I need to create a String placed in a TextView that will display a string like this: First Part Not Bold BOLD rest not bold So I want to know how I could use SpannableStringBuilder to do this? I could use three TextEdit to accomplish this but I…
Code Droid
  • 10,344
  • 17
  • 72
  • 112
8
votes
2 answers

android SPAN_EXCLUSIVE_EXCLUSIVE not working properly

I am trying to set span on a SpannableStringBuilder using flag SPAN_EXCLUSIVE_EXCLUSIVE and I am facing problem on further editing the text to which I am setting span. Expected behaviour 1: Original text. 2: Text added before. 3: Text added after…
7
votes
2 answers

SpannableStringBuilder replace content with Regex

I have the following code in which I am going to mark the contents between the curly braces with SpannableString and remove the curly braces but it gives wrong result. String text = "the {quic}k brown {fox} jumps {over} the lazy dog. {A Quick}…
Muhammad
  • 6,725
  • 5
  • 47
  • 54
5
votes
0 answers

Font wasn't applied when setting TextAppearanceSpan to SpannableStringBuilder for api 26 and below

I'm trying to set a TextAppearanceSpan to SpannableStringBuilder. It works for API 27 and above, but I can't find a solution for api 26 and below. Here is the code i'm using: fun getMenuSpannable(context: Context, title: String):…
5
votes
3 answers

How to make ClickableSpan links in MaterialAlertDialogBuilder clickable?

I have a SpannableStringBuilder object with a ClickableSpan link like this, SpannableStringBuilder ssb = new SpannableStringBuilder("Hi StackOverflow!"); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void…
4
votes
1 answer

Why does adding an ImageSpan to a Snackbar's action text work on Android devices SDK level 26 but not on SDK level 25?

I want to show a Snackbar and use an image instead of text for the action. I use the following code: val imageSpan = ImageSpan(this, R.drawable.star) val builder = SpannableStringBuilder(" ") builder.setSpan( imageSpan, …
fweigl
  • 21,278
  • 20
  • 114
  • 205
4
votes
5 answers

Android Spannable not working in recycler view adapter

I have a recycler view and want to change color of some part of textview text. Here's my code: public class MyAdapter extends RecyclerView.Adapter { public ArrayList wageItemList; private…
WOLF.L
  • 374
  • 5
  • 15
3
votes
1 answer

How would I scale multiple spans using SpannableStringBuilder?

I have this working, but redundant, code: feedbackView.text = SpannableStringBuilder() .scale(.6f) { italic { append(getString(R.string.suggestion_prefix)) } } .scale(.6f) { append("\n\n") } .scale(.6f) { bold { append(s) } } How would…
Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101
3
votes
2 answers

Add extra line in SpannableStringBuilder getSpans()

I am combining different strings to show in a TextView. I am doing this using a SpannableStringBuilder, as I need to apply a different color to a few substrings in the string. Now in the combined strings, there are urls which I show in different…
user3034944
  • 1,541
  • 2
  • 17
  • 35
3
votes
0 answers

Oreo 8.0,8.1:IndexOutOfBoundsException for SpannableStringBuilder.setSpan

Following error found on Oreo version 8.0 and 8.1, but working fine on other Android versions. java.lang.IndexOutOfBoundsException: at android.text.SpannableStringBuilder.checkRange (SpannableStringBuilder.java:1314) at…
Vasu
  • 886
  • 2
  • 11
  • 28
3
votes
2 answers

How to detect specific Words in SpannableStringBuilder android?

I want to know how can i detect some specified words in SpannableStringBuilder . My purpose is to change color of this words. Say i have SpannableStringBuilder span and the list included my Words like "Name" , "Family" , "Location" etc. In this…
Shahin Ghasemi
  • 1,600
  • 1
  • 20
  • 38
3
votes
1 answer

SpannableStringBuilder.getSpans() sort order is wrong on nougat 7.0/7.1

the following code works on everything I try between 2.3 and 6.0.1 but fails 7.0/Emulator and 7.1.1/Nexus 6P SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); for (int i=0;i<5;++i) { int p =…
SteelBytes
  • 6,905
  • 1
  • 26
  • 28
2
votes
3 answers

Android : Adding an imageview right at the end of a textview via ImageSpan and make the image clickable

I want to achieve a design as shown above in the screenshot. The image is fetched from a URL and I want to add a click listener in the image only. Tried using Image span but with no success. Could somebody help me through this? Thank you
viper
  • 1,836
  • 4
  • 25
  • 41
2
votes
0 answers

atal Exception: java.lang.IndexOutOfBoundsException setSpan (4 ... 4) ends beyond length 3 only occuring on Nexus 5X devixes

I see this crash for a while now in my crashlytics and I cannot find a way to fix it. It only occurs on Nexus 5X devices with Android 6.0.1. Crashlog: Fatal Exception: java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 3 …
2
votes
1 answer

Use spannable in a loop for a mutable text

So my app should compare the user's input with a random quote provided by the app, and I want to color the correct word with green and the wrong one with red. the problem is that I don't know how to do it with Spannable in a loop, and especially…
1
2 3 4 5