I want to apply two different font styles to a text in a single TextView.
My case is same as Android - two sentences, two styles, one TextView. The only difference is that I want to set a Custom Font on the whole text. I have included Helvetica Font as an assets in my project and want to apply that font to the TextView with first part of the text will be Helvetica BOLD and remaining part Helvetica NORMAL. Any suggestions how it can be done ?
Text needed in following format. Custom text with different styles and single textview.
You can create a custom view and render your text with Two Paint objects using canvas.drawText method
did you try setting a custom typeface on the TextView before applying spanable text ?
and then apply SpannableStringBuilder as from the linked question - I'm only assuming that if your ttf supports 'normal' and 'bold' it would render accordingly :)
One way to do this is to extend TypefaceSpan:
Then when you want to use two different typefaces call:
This may work - create your own custom TextView and then use a StyleSpan on one part of it:
And then you can do something like:
I use this approach
As you can see "Author", "Title" and "Tags" are set to BOLD
Screenshot http://image.prntscr.com/image/dd60bb4a335445c2adca8a4596d7fb32.png
Here is a solution more straightforward, you can use HTML to set different styles on the same
TextView
.For example:
You need the following import: