We can use the custom font in our applications. we can use *.ttf files in application for this purpose just follow these given steps.
1) main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1" >
<TableRow>
<TextView
android:id="@+id/file"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="80sp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/file2"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="60sp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/file3"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="120sp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/file4"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="40sp" />
</TableRow>
<TableRow android:id="@+id/text_hide">
<TextView
android:id="@+id/file5"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="60sp" />
</TableRow>
</TableLayout>
2) enter a string entry in strings.xml
<string name="jitesh">Jitesh Upadhyay</string>
3)CustomFontExampleActivity.java
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.TextView;
import java.io.File;
public class CustomFontExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.file);
Typeface face = Typeface.createFromAsset(getAssets(),"fonts/CHOCD.otf");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file2);
face = Typeface.createFromAsset(getAssets(),"fonts/ABADDON.TTF");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file3);
face = Typeface.createFromAsset(getAssets(),"fonts/ANGEL.otf");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file4);
face = Typeface.createFromAsset(getAssets(),"fonts/NorthernTerritories.ttf");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file5);
face = Typeface.createFromAsset(getAssets(),"fonts/WoodWud.ttf");
tv.setTypeface(face);
}
}
1) main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1" >
<TableRow>
<TextView
android:id="@+id/file"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="80sp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/file2"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="60sp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/file3"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="120sp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/file4"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="40sp" />
</TableRow>
<TableRow android:id="@+id/text_hide">
<TextView
android:id="@+id/file5"
android:gravity="center_horizontal"
android:text="@string/jitesh"
android:textColor="@color/aqua"
android:textSize="60sp" />
</TableRow>
</TableLayout>
2) enter a string entry in strings.xml
<string name="jitesh">Jitesh Upadhyay</string>
3)CustomFontExampleActivity.java
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.TextView;
import java.io.File;
public class CustomFontExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.file);
Typeface face = Typeface.createFromAsset(getAssets(),"fonts/CHOCD.otf");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file2);
face = Typeface.createFromAsset(getAssets(),"fonts/ABADDON.TTF");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file3);
face = Typeface.createFromAsset(getAssets(),"fonts/ANGEL.otf");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file4);
face = Typeface.createFromAsset(getAssets(),"fonts/NorthernTerritories.ttf");
tv.setTypeface(face);
tv = (TextView) findViewById(R.id.file5);
face = Typeface.createFromAsset(getAssets(),"fonts/WoodWud.ttf");
tv.setTypeface(face);
}
}
4) make a fonts folder inside assets folder and put font files inside this .
get fonts from the link
http://cooltext.com/Fonts-A
No comments:
Post a Comment