Dhanesh
Dhanesh

Reputation: 781

How to set custom fonts in bold styles

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);

Upvotes: 10

Views: 9730

Answers (4)

Stanojkovic
Stanojkovic

Reputation: 1632

Late answer but maybe helpful:

textView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/BRADHITC.otf"), Typeface.BOLD);

This way i have changed TextView appearance of SlidingTabLayout.

Upvotes: 2

robkriegerflow
robkriegerflow

Reputation: 716

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:

  1. 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

  2. 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"/>
    
  3. At the top of my Activity, declared a TextView object:

    private TextView myTextView;
    
  4. 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);
    

Upvotes: 2

Harshad
Harshad

Reputation: 8014

DEFAULT_BOLD is of type Typeface. Typeface.create() requires int.

Here is correct one

Typeface bold = Typeface.create(tf, Typeface.BOLD);  

Upvotes: 10

Vamshi
Vamshi

Reputation: 1495

Try this

tv.setTypeface(null, Typeface.BOLD);

Upvotes: 4

Related Questions