Learn ,How to use Custom Font in android.

 

 

 

If you are unable to locate asset folder then create one by following the following steps as shown in the image (right click the app folder)

creating asset folder.png

  • Create layout or your app “activity_main.xml”
    </pre>
    <pre><?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000">
    
        <TextView
            android:id="@+id/txtCustomFont"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#fd8b22"
            android:layout_centerInParent="true"
            android:textSize="50dp"
            android:text="Awesome"/>
    
    </RelativeLayout></pre>
    <pre>
    
  • Now open your activity “MainActivity.java”, In onCreate() write
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            TextView tv = (TextView) findViewById(R.id.txtCustomFont);
            Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Mostwasted.ttf");
            tv.setTypeface(font);
        }
    
    

 

 

  • Bingo, now run your app.

Know more about assest: http://stackoverflow.com/questions/5583608/difference-between-res-and-assets-directories