I have downloaded custom font to use on my app. I want to set style bold for that font. I have used the following code but its not working:
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/BRADHITC.otf");
Typeface bold = Typeface.create(tf, Typeface.DEFAULT_BOLD);
TextView tv = (TextView) findViewById(R.id.cou_text);
tv.setTypeface(tf);
Neither of these answers worked for me.
Maybe they worked for others, but the way I got the bold version of a font working in my program, I did the following:
Copy/pasted the font .ttc - in this case AmericanTypewriter.ttc - to a folder I created in my main/assets/ directory called /fonts. So, main/assets/fonts/AmericanTypewriter.ttc
I made sure I had a TextView with an id in my xml:
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is American Bold"/>
At the top of my Activity, declared a TextView object:
private TextView myTextView;
In the same Activity's onCreate(), inserted the following code:
Typeface americanFont = Typeface.createFromAsset(getAssets(),
"fonts/AmericanTypewriter.ttc");
Typeface americanFontBold = Typeface.create(americanFont, Typeface.BOLD);
myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setTypeface(americanFontBold);
DEFAULT_BOLD is of type Typeface. Typeface.create() requires int.
Here is correct one
Typeface bold = Typeface.create(tf, Typeface.BOLD);
Try this
tv.setTypeface(null, Typeface.BOLD);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With