Font
You have to put question
“hey, can we change Text font our application?” Answer is depends on which your
platform comes with this font. Whether you can add other fonts, and how
to apply them to the widget or whatever needs the font change?
Android
natively used three font knows, of "sans", "serif", and "monospace". you have change font in .xml class ,{ android:typeface="monospace"}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SARVESH KAUSHIK"
android:typeface="monospace"
android:textSize="20dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SARVESH KAUSHIK"
android:typeface="sans"
android:textSize="20dp"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SARVESH KAUSHIK"
android:typeface="serif"
android:textSize="20dp" />
</LinearLayout>
More Font
You have add more font via assets folder .The easiest way to accomplish this is to package the desired font(s) with your application.Simply create an assets/ folder in the project root, and put your True-type (TTF) fonts in that folder. You might, for example, create assets/fonts/ and put your TTF files there.
Then your widgets to use that font. Unfortunately, you can no longer use
layout XML for this, since the XML . Instead, you need to make the change in Java code:
public class Font extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.newfont);
Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/HandmadeTypewriter.ttf");
tv.setTypeface(face);
}
}
0 comments