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
2 answers

How to implement a SpannableStringBuilder where only a certain part is colored?

I need to implement a string that changes the color of some parts of it to highlight it. I need to create something like a hotkey guide that displays the action you could perform by pressing the highlighted number. I used to use Html. from HTML but…
BlueGreen
  • 1
  • 6
0
votes
1 answer

html converted bold or italic spanned string in android

I have method in my custom EditText that makes the text bold or italic here is my method: public boolean changeTextStyle(TextStyle style) { if (isTextSelected()) { int startSelection = getSelectionStart(); int endSelection =…
0
votes
2 answers

change string color programmatically depending if condition

Is it possible to set multiple colors for different pieces of text inside a TextView with if condition? Here is my code: mColoredText = findViewById(R.id.questionText); String mColoredString = "BLACK RED GREEN YELLOW ORANGE BLUE WHITE"; …
0
votes
1 answer

not able to change color of a part of text in EditText

I want to change the color of some part of text in EditText. I am trying following code, but it is not working. SpannableStringBuilder ssb=new SpannableStringBuilder(expression); ForegroundColorSpan fcs=new…
0
votes
0 answers

How to add padding to SpannableStringBuilder?

I have the following code, thanks to the help of @TangXianQiang which creates a background that is wrapped tightly around the text in a TextView: String str="this bit of text spans more than one line.Words words words"; int bstart=0; int…
Paradox
  • 4,602
  • 12
  • 44
  • 88
0
votes
0 answers

How to set text color in EditText for part of text?

I have an EditText and I need to highlight some text i.e. change the color of pieces of text. I am using SpannableStringBuilder with ForegroundColorSpan to set text color. The problem is (on some devices, for example Lenovo s90) if I have some text…
Aleksandr
  • 787
  • 6
  • 22
0
votes
0 answers

Inconsistent behavior of SpannableStringBuilder Android 7.0

I have to show some characters or numbers in superscript and subscript in TextView. So I use SpannableStringBuilder but in Nougat its output is inconsistent. public class MainActivity extends AppCompatActivity { ArrayList
0
votes
0 answers

Android: how to use custom IME without intermediate EditText

I followed this tutorial to create a custom IME and am pretty happy with the result: https://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615 However, when I click on an EditText to start typing, my keyboard is opened…
0
votes
1 answer

What is flag variable in building SpannableStringBuilder

I read flags parameter in google docs, but I can't find what exactly it's doing. For example in below code: SpannableStringBuilder builder1 = new SpannableStringBuilder(); builder1.append("hi"); builder1.append("this is test"); builder1.setSpan(new…
Hojjat
  • 815
  • 1
  • 10
  • 25
-1
votes
1 answer

How to Bold (Span) the searched text in string dynamically?

I have a string, in which i have to find a word being searched from end user and make it bold to highlight. Example: String : Address must have a format. Address can be of multiple line. Required Text: Address must have a format. Address can be…
Punit Sharma
  • 2,951
  • 1
  • 20
  • 35
-1
votes
1 answer

Android Editable is abstract; cannot be instantiated

I'm creating an EditText subclass and I want to make an Editable variable to pass to the super class. When I originally tried private Editable unicodeText = new Editable(); I got the error 'Editable' is abstract; cannot be…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
-2
votes
1 answer

SpannableStringBuilder not working in some devices

SpannableStringBuilder decorations not working in some devices . I am setting typeface, font color using SpannableStringBuilder in java code and setting in the textview .
ArpitA
  • 721
  • 7
  • 17
-3
votes
1 answer

SpannableStringBuilder append() NullPointerException

// Documentation from interface public SpannableStringBuilder append(CharSequence text) { int length = length(); return replace(length, length, text, 0, text.length()); } SpannableStringBuilder source code append() function doesn't avoid…
-4
votes
2 answers

Android highlight multiple words

String highlightedWords[] = {"We", "country"}; String fullText = "We love our country a lot."; output will be like this: We love our country a lot.
1 2 3 4
5