Friday, September 21, 2012

Android Set Font in xml and Java


android set font

In SDK Android provides three Droid fonts. Which are Droid sans , Droid Sans Mono and Droid Serif . We can set these system fonts to your android control either in XML or in Java Code.


1. Setting Font in XML layout.
Use android:typeface property in your control to set the system fonts. see the code below.

-------------------------------------------------------------------------------------
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/rowTextView"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:padding="10dp"
 android:textSize="18dp"
 android:typeface="serif"
/ >
-------------------------------------------------------------------------------------

In the above example.. i am used a TextView control to set the font serif


2. Setting Font using Java code.

-------------------------------------------------------------------------------------
TextView textView = (TextView) findViewById(R.id.TextView1);
textView.setTypeface(Typeface.SERIF);
-------------------------------------------------------------------------------------
In the above code setTypeface() method is used to set the TextView font to serif.

0 Responses to “Android Set Font in xml and Java”

Post a Comment