FAQ Database Discussion Community


Android: TextView with multiples colors and fonts

android,textview,spannablestring
Ok, so I gather that this should be a fairly straightforward process. I've read the following questions: Multiple Typefaces in the same TextView Multiple Typefaces in the same TextView Put in bold some parts of a TextView Making part of a string bold in TextView The advice seems to be...

Modify Drawable inside SpannableStringBuilder and DynamicLayout

android,android-drawable,spannablestring,imagespan
I'm trying to hide a smiley in a SpannableStringBuilder (which is used in a DynamicLayout). At first I tried ImageSpan[] spans = spannable.getSpans(0, length, ImageSpan.class); spans[0].getDrawable().setAlpha(0); It didn't work. I also tried ImageSpan[] spans = spannable.getSpans(0, length, ImageSpan.class); spans[0].getDrawable().setVisible(false, true); Didn't work either. The next code did work, but it...

SpannableString on button not works for API21?

android,android-5.0-lollipop,spannablestring
I try to put an icon on the toggle button by using SpannableString. and working on API17 but not on API21. As you can see, It's work on Button and TextView for API17 but work on TextView only on API21 (The 'Z' is not replace by icon). private SpannableStringBuilder createSpanIcon(int...

spannablestring is not working for programatically createed button

android,android-textview,spannablestring
I know SpannableString is possible to set different text size in one textview but if textview is added programatically its not working. String s = "Best Ever"; SpannableString ss1 = new SpannableString(s); ss1.setSpan(new RelativeSizeSpan(2f), 0, 4, 0); // set size ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0); // set color TextView tv...

Android set clickable text to go one fragment to another fragment

java,android,android-fragments,spannablestring
I need to do something like this. Suppose I have 2 fragments A and B.There is a text which can be clickable in fragment A and when user click this text , he can go to fragment B. This example helped me to do it but I think it does...

Loading lots of Text (spannablestring) into Android textview taking 200ms plus?

android,textview,scrollview,lazy-loading,spannablestring
I'm currently developing a Bible in Android which is Paragraph based so a ListView won't work. I implemented a ViewPager using fragments for each new chapter that is loaded. The problem I'm having is that when I set the TextView text (mytextview.settext()), it takes over 200 ms just to display...

TabStopSpan.Standard constructor parameter

android,textview,spannablestring
Does anyone knows what the parameter (where) in the TabStopSpan.Standard constructor represents ? is it pixels ? According to some tests that I did, it doesn't represent pixels, I simply draw gridline and added tab stop to textview, and if for example I set the tab to 200 it doesn't...

Clickable SpannableString in android

android,spannablestring
I have the bellow code: SpannableString ss = new SpannableString("Translators"); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View v) { // do something; } }; ss.setSpan(myClickableSpan, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); But when i add the SpannableString into a String is unclickable and not underline String thanks="Also thanks the "+ss;...

How to write SpannableString to parcel?

android,string,parcelable,spannablestring
In my application I have dialog which consists few SpannableString objects. Because this is dialog, I need to be able to store it when user leaves application and comes back to it later on. But the problem is how can I write SpannableString into Parcel?...

ForegroundColorSpan is not applied to ReplacementSpan

android,spannablestring
I'm trying to utilize ReplacementSpans to format the input in a EditText Field (without modifying the content): public class SpacerSpan extends ReplacementSpan { @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return (int) paint.measureText(text.subSequence(start,end)+" "); } @Override public void draw(Canvas canvas, CharSequence text, int...

NullPointerException when long press on TextView with SpannableString

java,android,textview,spannablestring
I have a TextView with SpannableString because I want the do differnet thing when user click different position of the view. Here is my code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); String str = "ClickMe"; SpannableString spStr = new SpannableString(str); ClickableSpan clickSpan = new...

Multiple RelativeSizeSpan on same line

android,android-layout,android-canvas,spannablestring
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();...