Using external font in Android Typeface Example
Kamis, 05 September 2013
0
komentar
Loading external fonts in android is very easy
1.Add your external fonts in assets folder
2.Create a Class Typeface_Utils
import android.app.Activity;
import android.graphics.Typeface;
public class Typeface_Utils {
static Typeface tf;
public static void Typeface_font(Activity activity)
{
//add new font and use it .settypeface(tf);
tf = Typeface.createFromAsset(activity.getAssets(),"abc.ttf");
}
}
3.Then we will create the layout as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Typeface_Sample"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
4.Then in your MainActivity.
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.textView1);
Typeface_Utils.Typeface_font(MainActivity.this);
tv.setTypeface(Typeface_Utils.tf);
}
}
1.Add your external fonts in assets folder
2.Create a Class Typeface_Utils
import android.app.Activity;
import android.graphics.Typeface;
public class Typeface_Utils {
static Typeface tf;
public static void Typeface_font(Activity activity)
{
//add new font and use it .settypeface(tf);
tf = Typeface.createFromAsset(activity.getAssets(),"abc.ttf");
}
}
3.Then we will create the layout as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Typeface_Sample"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
4.Then in your MainActivity.
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.textView1);
Typeface_Utils.Typeface_font(MainActivity.this);
tv.setTypeface(Typeface_Utils.tf);
}
}
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Using external font in Android Typeface Example
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://samsung-galaxy-s2r.blogspot.com/2013/09/using-external-font-in-android-typeface.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar