I wanna use custom font file. For that below is my code
XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<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>
Java code:
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");
txt.setTypeface(font);
Its working. But I want to use this custom fonts for whole project.
So i have to put in a place where all Class can use it.No need to write for every TextView.
Where and how can I use this custom font.
You can make a custom TextView extend TextView to set custom fonts.
TextViewPlus.java:
attrs.xml: (in res/values)
main.xml:
You would put “Chantelli_Antiqua.ttf” in the assets folder.
EDIT: Look at these Questions Using a custom typeface in Android
Android: Want to set custom fonts for whole application not runtime
Custom fonts and XML layouts (Android)
Tutorials:
Custom XML Attributes For Your Custom Android Widgets
Using Custom fonts on Android