-3

I tried to display "hello world !" by designing an app using a custom font stored in src/Main/CustomF/times.ttf in my laptop.....while execution it disappears very soon telling that "unfortunately your app stopped"....my coding is as below.....please help me..

package com.example.nambimanavalan.customfonts;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class MainActivity extends Activity {

    TextView t;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t=(TextView)findViewById(R.id.mine);
        Typeface custom=Typeface.createFromAsset(getAssets(),"CustomF/times.ttf");
        t.setTypeface(custom);

    }
}
BackSlash
  • 21,927
  • 22
  • 96
  • 136

2 Answers2

1

you need to put your font in assets/Font folder and than you can use

 Typeface custom=Typeface.createFromAsset(getAssets(),"Font/times.ttf");
Ravi
  • 34,851
  • 21
  • 122
  • 183
0

put your custom font in : assets/CustomF/times.ttf and maybe then it will work

assets folder is directly under your project folder, and whenever you create a fresh project it is empty.

Sarthak Mittal
  • 5,794
  • 2
  • 24
  • 44