Using Custom Fonts in Android Mobile Application

Place the TTF file in the ./assets directory (create it if it doesn’t exist yet).
We’re going to use a basic layout file with a TextView, marked with an id of “custom_font” so we can access it in our code.
 
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
              android:orientation="vertical"  
              android:layout_width="fill_parent"  
              android:layout_height="fill_parent"  
        >  
  
    <TextView  
            android:id="@+id/custom_font"  
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"  
            android:text="This is the Chantelli Antiqua font."  
            />  
  
</LinearLayout>  
 
Open your main activity file and insert this into the onCreate() method:

TextView txt = (TextView) findViewById(R.id.custom_font);  
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");  
txt.setTypeface(font);  
 
If you put a folder under the asset, you need to make the change in Java code, by calling Typeface.createFromAsset(getAssets(), "fonts/Chantelli_Antiqua.ttf"),

Bu blogdaki popüler yayınlar

About Android padding, margin, width, height, wrap_content, match_parent, R Class

@SerializedName and @Expose annotations