spannablestringbuilder

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

笑着哭i 提交于 2020-02-06 09:03:25
问题 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("<b>Test</b> : 10", Html.FROM_HTML_MODE_LEGACY) Gives Test : 10 Html.fromHtml("<b>Test</b> : >10", Html.FROM_HTML_MODE_LEGACY) Gives Test : >10 but Html.fromHtml("<b>Test</b> : <10", Html.FROM_HTML_MODE_LEGACY) Gives Test : 回答1: You have to use < to show < using Html. Html.fromHtml("<b>Test</b> : <10", Html.FROM

How to have a SpannableStringBuilder append a span that's inside a formatted string?

雨燕双飞 提交于 2019-12-05 07:31:04
问题 Background Suppose I use SpannableStringBuilder to append multiple stuff into it, and one of them is string that I format from the strings.xml file, which has a span inside: SpannableStringBuilder stringBuilder = new SpannableStringBuilder (); stringBuilder.append(...)... final SpannableString span = new SpannableString(...); span.setSpan(new BackgroundColorSpan(0xff990000), ...,...,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.append(getString(R.string.string_to_format, span));

SpannableStringBuilder replace content with Regex

偶尔善良 提交于 2019-12-05 00:31:59
问题 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} {brow}nfoxjumpsoverthelazydog"; tv.setText(makeSpannable(text, "\\{.*?\\}")); public SpannableStringBuilder makeSpannable(String text, String regex) { SpannableStringBuilder spannable = new SpannableStringBuilder(text); Pattern pattern = Pattern.compile

SpannableStringBuilder replace content with Regex

不羁的心 提交于 2019-12-03 15:11:34
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} {brow}nfoxjumpsoverthelazydog"; tv.setText(makeSpannable(text, "\\{.*?\\}")); public SpannableStringBuilder makeSpannable(String text, String regex) { SpannableStringBuilder spannable = new SpannableStringBuilder(text); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(spannable.toString()); while (matcher.find()) { String word

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

落爺英雄遲暮 提交于 2019-11-27 00:02:09
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 would like to use best solution. Azhar Shaikh First Part Not Bold BOLD rest not bold You can do this either as @Rajesh suggested or by this. String normalBefore= "First Part Not Bold "; String normalBOLD= "BOLD "; String normalAfter= "rest not bold"; String finalString= normalBefore+normalBOLD+normalAfter; Spannable sb = new SpannableString( finalString

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

淺唱寂寞╮ 提交于 2019-11-26 08:49:43
问题 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 would like to use best solution. 回答1: First Part Not Bold BOLD rest not bold You can do this either as @Rajesh suggested or by this. String normalBefore= "First Part Not Bold "; String normalBOLD= "BOLD "; String normalAfter= "rest not bold"; String