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

541 questions
6
votes
2 answers

How to set multiple spans on a TextView's text (clickable and bold)

mSpannableString = new SpannableString("12:00PM"); mSpannableString.setSpan(clickableSpan, 0, 7, 0); mSpannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, 7, 0); TextView textView = new TextView(getContext()); …
Harshith
  • 397
  • 1
  • 6
  • 17
6
votes
3 answers

Android - Add Margin for SpannableStringBuilder using ReplacementSpan

I'm trying to format Hashtags inside a TextView/EditText (Say like Chips mentioned in the Material Design Specs). I'm able to format the background using ReplacementSpan. But the problem is that I'm not able to increase the line spacing in the…
PsyGik
  • 3,535
  • 1
  • 27
  • 44
6
votes
1 answer

Set Drag Listener on SpannableString

Im trying to set an OnDragListener to certain words of a TextView using SpannableString. Im able to add an OnClick Listener by using ClickableSpan by doing hashText.setSpan(new ClickableSpan() { So I figured I would try the same but replace…
user1446988
  • 333
  • 1
  • 6
  • 22
6
votes
1 answer

Set text by multiple span styles by iterating fails

I set few words by multiple span styles and when I pass array with styles to method, in the result only the last word has that styles. It ommits the other words. Why? Below my code and execution. Thank You in advance. //execution in…
deadfish
  • 11,996
  • 12
  • 87
  • 136
6
votes
2 answers

How to remove span style from SpannableString

I was trying to remove style from my SpannableString but unfortunately is not working, my aim is to remove the style when I click on the text. SpannableString content = new SpannableString("Test Text"); content.setSpan(new…
SingaCpp
  • 85
  • 1
  • 4
6
votes
2 answers

Finding EditText Editable getSpans Start and End Index

I am trying to get All Spans applied to text as below; public String getTextWithTags(Editable e) { StyleSpan[] ss = e.getSpans(0,e.length(),StyleSpan.class); ss[0].getSpanStart <--- ? This is the problem, no such function return…
Mert Serimer
  • 1,217
  • 2
  • 16
  • 38
6
votes
1 answer

Spannable Text is not working in Dialog Fragment

I have added TextView in my Dialog Fragment and i show Spannable data Dynamically in this TextView. But it's not apply Spannable effect to the text. Here is my code to generate Three Spannable String and added into TextView. TextView …
M D
  • 47,665
  • 9
  • 93
  • 114
6
votes
0 answers

Correct way to trigger a refresh in a custom drawable inside a textSpan

I have written a custom span for SpannableStrings "ImageURLSpan" that extends ImageSpan. The ImageSpan is configured with a Drawable "RemoteImageDrawable" that renders a static placeholder, loads an image from the internet, then when the image has…
rupps
  • 9,712
  • 4
  • 55
  • 95
6
votes
2 answers

Clone SpannableStringBuilder

I am working on an Activity in which I parse a text with markup characters. What I'm doing is converting them to several types of ClickableSpans. The problem is that I need to implement a function (lets call it function B) that implies having…
Cruclax
  • 394
  • 3
  • 13
6
votes
2 answers

How to set custom font for word in a TextView text

I want to set custom font for a word which is appears any where in a string. Ex : Hai @abc how are you ? , Hello my dear friend where you @abc In the above examples, i have to apply custom font for "abc". I tried with Spannable class, but i am…
koti
  • 1,071
  • 3
  • 15
  • 35
6
votes
3 answers

Ellipsize individual lines of a SpannableString in a TextView

I have a TextView storing an address that is two lines long. The street goes on the first line and is bold. The city & state go on the second line and are not bold. I want the end of each line ellipsized if the individual text on that line runs…
erin
  • 1,130
  • 3
  • 17
  • 28
6
votes
3 answers

StringIndexOutOfBoundsException from SpannableStringInternal

I keep recieving the following bug reports from the market: java.lang.StringIndexOutOfBoundsException: length=51; regionStart=37; regionLength=-15 at java.lang.String.startEndAndLength(String.java:593) at java.lang.String.getChars(String.java:902)…
Croc
  • 485
  • 5
  • 14
5
votes
0 answers

Memory leak in SpannableString, dependent on WHERE I put the ClickableSpan

So,.... I've got this code (onStart): ss = new SpannableString(getString(R.string.legal_user_acceptance_disclaimer)); ss.setSpan(clickableSpanTermsOfUse, 32, 44, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); which leak the parent-Activity (those lines are…
murkr
  • 634
  • 5
  • 27
5
votes
0 answers

In StyleSpan, why Typeface to NORMAL can not be applied over the Typeface to BOLD?

Button btnBold = (Button) findViewById(R.id.btnBold); btnBold.setOnClickListener(new OnClickListener() { @Override public void onClick (View v){ startSelection = etx.getSelectionStart(); endSelection =…
5
votes
0 answers

Setting underline span in edittext without removing autosuggest

I didn't expect this to be a problem but I cant simply underline words in my edittext because of the underline in softkeyboard's autosuggest feature which automatically underlines a selected word .However I still want to keep the feature while…