Asim Krishna Das Asim Krishna Das - 3 months ago 14
Android Question

How to use custom font in Android Studio

I was trying to use custom font in Android Studio as we did in Eclipse. But unfortunately could not figure out where to put the 'assets' folder!

Answer

Here is the few steps to solve it:

  1. Go to the (project folder)
  2. Then app>src>main
  3. Create folder 'assets>fonts' into the main folder.
  4. Put your 'abc.ttf' into the fonts folder.

        AssetManager am = context.getApplicationContext().getAssets();
    
        typeface = Typeface.createFromAsset(am,
                String.format(Locale.US, "fonts/%s", "abc.ttf"));
    
        setTypeface(typeface);
    

    or try this way:

       TextView tx = (TextView)findViewById(R.id.textview1);
    
       Typeface custom_font = Typeface.createFromAsset(getAssets(),  "fonts/abc.ttf");
    
       tx.setTypeface(custom_font);