I should point out that the faux bold probably looks terrible because of how thin this font is. I tried a different TTF file and it looked OK. Either way, using two completely different fonts in the same TextView would be another use-case.
On Sep 23, 3:42 pm, Richard Leggett <richard.legg...@gmail.com> wrote: > I've done quite a lot of digging around the 1.6 SDK source code for > this one. My aim is simply to have 2 StyleSpans within a TextView, one > containing bold text, the other normal, both using a custom font. > > I'm setting the typeface to a custom font which was created in this > fashion: > > // utility class > public static Typeface getTypewriter(Context context) { > if(typewriter == null) > typewriter = Typeface.createFromAsset(context.getAssets(), > "fonts/ > americantypewriter-medium.otf"); > return typewriter;} > > ... similar function for for getting bold face ... > > // usage > textView.setTypeface(Typefaces.getTypewriter(mContext), > Typeface.NORMAL); > textView.setTypeface(Typefaces.getTypewriterBold(mContext), > Typeface.BOLD); > SpannableStringBuilder builder = new SpannableStringBuilder("Hello > World"); > builder.setSpan(new StyleSpan(Typeface.BOLD), 0, 4, > Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); > builder.setSpan(new StyleSpan(Typeface.NORMAL), 5, 9, > Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); > textView.setText(builder); > > Based on the source, I can see that calling setTypeface() twice just > overwrites the previous call, even when the style param is different. > So in my case the entire TextView appears in bold. I'm kind of hoping > there's a way to do it given you can use BOLD and NORMAL when using a > built-in font. > > Does anyone have any workarounds? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en