0

I have one quote application in which I have given option to choose font from assets for text view. its like below

text_quotes.setTypeface(Typeface.createFromAsset(getAssets(), image));

I have another function in which I want give option to make text bold,italic etc. I have tried it like below code

text_quotes.setTypeface(null,Typeface.BOLD);

but this is changing font to default...How can I make it BOLD etc with same font which applied to text view ?

I am learning android yet...so ignore if My question is very easy. Thanks

Priya
  • 1,602
  • 4
  • 22
  • 37
  • 1
    Instead of passing **null**, pass the typeface. Isn't it **obvious**? By passing null, you are re-setting the default font. – Phantômaxx Aug 31 '17 at 16:43

2 Answers2

1

Use this

textView.setTypeface(textView.getTypeface(), Typeface.BOLD);  

When you are passing null it returns the default Typeface

Kartik Shandilya
  • 3,796
  • 5
  • 24
  • 42
  • 1
    Hi ! Thanks its working....I am accepting your answer....when I want remove Bold from text view....textView.setTypeface(textView.getTypeface(), Typeface.NORMAL); ...I have tried this but its not changing back to normal...any idea what is wrong in this ? Thanks – Priya Aug 31 '17 at 16:51
  • In that case pass null instead of getTypeface to check if it works. – Kartik Shandilya Aug 31 '17 at 17:24
0

Use textView.setTypeface(TypeFace.BOLD);

It works for me.