1

I want to use Roboto font for All views in my android application ,how can I do that?

  • On the answers below, be care of memory leaks when using Typeface createfromasset. Do a search for that problem. Your question has also been covered before. – logray Feb 01 '13 at 16:11

2 Answers2

1

Create custom view such as TextView, EditText, etc.. Then you set in the constructors the setTypeface example below:

public class RobotoTextView extends TextView {

    public RobotoTextView(Context context) {
        super(context);
        setTypeface(Typeface
                .createFromAsset(context.getAssets(), "fontname.ttf"));

    }
}

And then just use this in you're layout, instead of using the standard TextView use your custom class example below:

<packagename.RobotoTextView
            style="@style/usecustomstyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/yourid"/>
QVDev
  • 1,093
  • 10
  • 17
0

use Typeface. Put your font file in assest folder. And then write below code.

 Typeface Roboto = Typeface.createFromAsset(getAssets(), "Roboto.ttf"); 

And then use Roboto font all your TextView,EditText..etc

  Textview.setTypeface(italic);  
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22