spannablestring

How to set multiple spans on a TextView's formatted text with placeholder, using customized span?

余生长醉 提交于 2019-12-08 04:25:52
问题 Background I know how to set multiple spans on a partial text within a static text, as I've asked here : final SpannableString text = new SpannableString("Hello stackOverflow"); text.setSpan(new RelativeSizeSpan(1.5f), text.length() - "stackOverflow".length(), text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new ForegroundColorSpan(Color.RED), 3, text.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(text); This will set the "stackOverflow" to have 2 spans on

Multiple RelativeSizeSpan on same line

拈花ヽ惹草 提交于 2019-12-07 13:06:50
问题 I'm trying to use two RelativeSizeSpan next to each other, but a big gap appears in between. See what I want to achieve and what I'm getting. This is how I'm building the Spanned instance String formattedValue = "25%"; SpannableStringBuilder ssb = new SpannableStringBuilder(formattedValue); ssb.append("\n"); ssb.append(otherValue); int firstSpanEnd = formattedValue.length(); ssb.setSpan(new RelativeSizeSpan(1.5f), 0, firstSpanEnd-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new

Need to center-align a single portion of text in a TextView

雨燕双飞 提交于 2019-12-07 10:20:24
问题 I'm currently using SpannableString to format a large block of text in a single TextView. The size and color are formatted just fine, but I'm struggling with alignment. I found this post that gave guidance on formatting for alignment, as well as this Android Developer page on how to use AlignmentSpan, but it doesn't seem to work for me. Eclipse shows no errors, the app loads/runs just fine, but the alignment piece seems to be completely ignored. Here's my code: Spannable t = new

Android TextView format multiple words

≡放荡痞女 提交于 2019-12-06 09:03:39
问题 Original String: Lorem ##ipsum## dolar ##sit## atem. Lorem ipsum dolar sit ##atem##. After formating: Lorem #ipsum dolar #sit atem. Lorem ipsum dolar sit #atem. But only the last one has the Formating i want. See image below. CODE private void format() { CharSequence text = editContent.getText(); MovementMethod movementMethod = editContent.getMovementMethod(); if ((movementMethod == null) || !(movementMethod instanceof LinkMovementMethod)) { editContent.setMovementMethod(LinkMovementMethod

Android create Spannable which does not wrap

自古美人都是妖i 提交于 2019-12-06 06:37:53
问题 I have a following issue with laying out text on Android. I'm basically trying to have two lines of text with minimal spacing and each should be styled differently. I've had quite good working solution with two singlelined TextViews one placed below the other, but I've been still getting a little bit cropped text on certain devices.. So I decided to switch to just one TextView an use Spannables instead which should be generally a better solution in all circumstances. That means I needed to

Android: using Spannable for putting text with bullets into TextView

柔情痞子 提交于 2019-12-06 06:04:44
问题 I need to put some text in a several languages. The text looks like: Title one two three Anouther Title one two three Bullets have different colour than anouther text. I heared about Spannable in Android , but unfortunaly I can use span only with from and end int values. The problem in that that in different languages my words will have different positions, and so spannable text is not for me. Could you help me to solve this in easy way. 回答1: I got so sick of dealing with bulleted text that I

Using custom font for part of a Text

杀马特。学长 韩版系。学妹 提交于 2019-12-06 03:40:49
Typeface robotoBold = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Bold.ttf"); Typeface robotoLight = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Light.ttf"); SpannableStringBuilder sb = new SpannableStringBuilder("This must be BOLd\nThis must be NORMAL"); sb.setSpan(robotoBold, 0, 17, Spannable.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(robotoLight, 18, 37, Spannable.SPAN_INCLUSIVE_INCLUSIVE); mTextView.setText(sb); This gives me a normal text for the whole TextView. Thank You. We are able to do this functionality font for part of a Text you have to use alter net

Multiple RelativeSizeSpan on same line

醉酒当歌 提交于 2019-12-05 18:36:19
I'm trying to use two RelativeSizeSpan next to each other, but a big gap appears in between. See what I want to achieve and what I'm getting. This is how I'm building the Spanned instance String formattedValue = "25%"; SpannableStringBuilder ssb = new SpannableStringBuilder(formattedValue); ssb.append("\n"); ssb.append(otherValue); int firstSpanEnd = formattedValue.length(); ssb.setSpan(new RelativeSizeSpan(1.5f), 0, firstSpanEnd-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new RelativeSizeSpan(0.3f), firstSpanEnd, firstSpanEnd+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); And this is how I'm

Need to center-align a single portion of text in a TextView

喜你入骨 提交于 2019-12-05 14:55:53
I'm currently using SpannableString to format a large block of text in a single TextView. The size and color are formatted just fine, but I'm struggling with alignment. I found this post that gave guidance on formatting for alignment, as well as this Android Developer page on how to use AlignmentSpan, but it doesn't seem to work for me. Eclipse shows no errors, the app loads/runs just fine, but the alignment piece seems to be completely ignored. Here's my code: Spannable t = new SpannableString("Test Blue."); t.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_blue)), 0, t

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

不打扰是莪最后的温柔 提交于 2019-12-05 13:09:27
问题 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(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textview1.setText("\n"+ss1+strhealth+"\n\n"); i want output to be like this Health: good where strhealth = good But it is coming out Health: good What is the mistake ? I am using android studio 2.1.1 回答1: String txt1="Health: ";