Questions tagged [spannablestring]

Android - SpannableString is a class for text whose content is immutable but to which markup objects can be attached and detached.

SpannableString is a class for text whose content is immutable but to which markup objects can be attached and detached used in Android development.

Reference

Android developer reference

526 questions
84
votes
10 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
  • 9,864
  • 16
  • 69
  • 111
65
votes
4 answers

How to set multiple spans on a TextView's text on the same partial text?

Suppose I have the next text : Hello stackOverflow And I wish to set the second word to be both RelativeSizeSpan (to set a relative font size) and TextAppearanceSpan (to set the color of the text) , how do I merge them both ? All I know is that I…
android developer
  • 106,412
  • 122
  • 641
  • 1,128
46
votes
4 answers

SpannableString: Is it possible to apply two or more RelativeSizeSpans?

I am trying to construct a SpannableString such that it looks like this: Two characters (m, s) should be smaller than the rest. I have tried to hold all the text in one SpannableString, and I also tried to concatenate two SpannableStrings via a…
manmal
  • 3,581
  • 1
  • 27
  • 39
39
votes
3 answers

Android SpannableString set background behind part of text

I would like to create something similar as seen on this image: I managed to create evertyhing with SpannableStringBuilder, except the orange rounded rectangle. I can set the background to that color with BackgroundColorSpan, but I can't find a way…
Roosevelt
  • 2,319
  • 1
  • 22
  • 34
37
votes
9 answers

How to make RelativeSizeSpan align to top

I have the following String RM123.456. I would like to Make RM relatively smaller Make RM aligned to top exactly I almost able to achieve it by using spannableString.setSpan(new RelativeSizeSpan(0.50f), 0, index,…
Cheok Yan Cheng
  • 49,649
  • 117
  • 410
  • 768
29
votes
5 answers

Combining Spannable with String.format()

Suppose you have the following string: String s = "The cold hand reaches for the %1$s %2$s Ellesse's"; String old = "old"; String tan = "tan"; String formatted = String.format(s,old,tan); //"The cold hand reaches for the old tan…
Maarten
  • 5,899
  • 6
  • 47
  • 80
23
votes
3 answers

Is there any way to insert an ImageSpan in a TextView without disrupting the text?

It seems that in order to add an ImageSpan to a Spannable in Android, I have to actually replace some text with the Image. For example: Spannable span = new SpannableString("Foo imageplace Bar!"); Drawable android =…
yuttadhammo
  • 4,879
  • 6
  • 32
  • 44
22
votes
1 answer

Best way to get a SpannableString from a SpannableStringBuilder

I am working in a wiki-like parser that creates spans for a set of markup tokens. It is working, but inside the token iterator I frequently need to convert the partial results on a SpannableStringBuilder to a SpannableString. This is called pretty…
rupps
  • 9,183
  • 4
  • 53
  • 87
20
votes
4 answers

Android Linkify text - Spannable Text in Single Text View - As like Twitter tweet

I have a textView and text like "This is the Simple Text with KeyWord and the Link to browse" in the above text i want to make.. clicking on the Link goes to open that URL AND clicking on that KeyWord open a new Activity in my…
MKJParekh
  • 32,883
  • 11
  • 84
  • 97
20
votes
6 answers

Why show java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String?

When copying String from any browser page, pasteData works properly. However when copying SpannedString from a message sent item editor(field), the application crashes and shows this error message: java.lang.ClassCastException:…
user4356416
19
votes
7 answers

how to have bold and normal text in same textview in android?

I have searched internet and tried the following code but its not working SpannableString ss1 = new SpannableString("Health: "); ss1.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), 0, ss1.length(),…
G.ONE
  • 423
  • 1
  • 4
  • 13
18
votes
1 answer

How to align TextView around an ImageView?

I am trying to align the TextView around ImageView. I am using the following code: private void createSpannableText(){ TextView myTextView = (TextView) findViewById(R.id.textView); SpannableStringBuilder builder = new…
Debopam Mitra
  • 1,720
  • 3
  • 24
  • 50
16
votes
3 answers

Android Justify spanable Text-view that support RTL Languages

I need to create a custom text-view in android, first of all it should be justified, then it should support spans and although it should support RTL (Right to Left) languages for ex: Farsi (Persian) ,... I'm working on this issue for a week! but In…
15
votes
1 answer

How to loop through the spans in a SpannedString or SpannableString in Android

If I have a SpannedString (or SpannableString) like this SpannableString spannableString = new SpannableString("Hello World!"); ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.RED); BackgroundColorSpan backgroundSpan = new…
Suragch
  • 364,799
  • 232
  • 1,155
  • 1,198
14
votes
1 answer

Adjusting text alignment using SpannableString

I have created a SpannableString, with the first character, and last 2 smaller than the rest. It looks like this: sBBBBss I would like to align the smaller characters so they are aligned with the top of the bigger text, instead of the bottom (as…
Booger
  • 18,137
  • 6
  • 51
  • 64
1
2 3
35 36