Simple and Custom Fonts
A set of presentable(Displayable and Printable) text characters in a specific size and style is known as Font. Typeface is the type design for a set of fonts, whereas Font Family formed from varieties of that design.
So Helvetica is Typeface Family, Helvetica Italic is a Typeface and Helvetica Oblique Regular or Helvetica Neue 10 is Font.
So Helvetica is Typeface Family, Helvetica Italic is a Typeface and Helvetica Oblique Regular or Helvetica Neue 10 is Font.
Simple Fonts
Android Studio have a default standard fonts, that are utilize by using it XML design as.
activity_main.xml
|
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif" android:text="sans-serif" android:textSize="28sp" android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif" android:text="sans-serif" android:textSize="28sp" android:textStyle="italic" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif" android:text="sans-serif" android:textSize="28sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif-condensed" android:text="sans-serif-condensed" android:textSize="28sp" android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif-condensed" android:text="sans-serif-condensed" android:textSize="28sp" android:textStyle="italic" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif-condensed" android:text="sans-serif-condensed" android:textSize="28sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="casual" android:text="casual" android:textSize="28sp" android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="casual" android:text="casual" android:textSize="28sp" android:textStyle="italic" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="casual" android:text="casual" android:textSize="28sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="cursive" android:text="cursive" android:textSize="28sp" android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="cursive" android:text="cursive" android:textSize="28sp" android:textStyle="italic" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="cursive" android:text="cursive" android:textSize="28sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="monospace" android:text="monospace" android:textSize="28sp" android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="monospace" android:text="monospace" android:textSize="28sp" android:textStyle="italic" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="monospace" android:text="monospace" android:textSize="28sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="serif-monospace" android:text="serif-monospace" android:textSize="28sp" android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="serif-monospace" android:text="serif-monospace" android:textSize="28sp" android:textStyle="italic" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="serif-monospace" android:text="serif-monospace" android:textSize="28sp" android:textStyle="bold" /> </LinearLayout> </ScrollView> |
Custom Fonts
To use third party Fonts in our application, we need to download it from their site and place it in Asset folder. First you need to create a folder with the names "Asset", and copy the downloaded font to that folder as
activity_main.xml
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/vibes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GreatVibes Regular"
android:textSize="28sp" />
<TextView
android:id="@+id/lobster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lobster"
android:textSize="28sp" />
<TextView
android:id="@+id/lobster_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lobster Two Regular"
android:textSize="28sp" />
<TextView
android:id="@+id/open_sans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Snasd Light"
android:textSize="28sp" />
<TextView
android:id="@+id/pacifico"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pacifico"
android:textSize="28sp" />
<TextView
android:id="@+id/roboto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roboto Black"
android:textSize="28sp" />
</LinearLayout>
|
MainActivity.java
|
public class MainActivity extends AppCompatActivity {
TextView greatVibes, lobster, lobsterTwoRegular, openSansLight, pacifico, robotoBlack;
private String GREATEVIBES_REGULAR = "GreatVibes-Regular.otf";
private String LOBSTER = "Lobster_1.3.otf";
private String LOBSTER_REGULAR = "LobsterTwo-Regular.otf";
private String OPENSANS_LIGHT = "OpenSans-Light.ttf";
private String PACIFICO = "Pacifico.ttf";
private String ROBOTO_BLACK = "Roboto-Black.ttf";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
greatVibes = (TextView) findViewById(R.id.vibes);
lobster = (TextView) findViewById(R.id.lobster);
lobsterTwoRegular = (TextView) findViewById(R.id.lobster_two);
openSansLight = (TextView) findViewById(R.id.open_sans);
pacifico = (TextView) findViewById(R.id.pacifico);
robotoBlack = (TextView) findViewById(R.id.roboto);
greatVibes.setTypeface(Typeface.createFromAsset(getAssets(), GREATEVIBES_REGULAR));
lobster.setTypeface(Typeface.createFromAsset(getAssets(), LOBSTER));
lobsterTwoRegular.setTypeface(Typeface.createFromAsset(getAssets(), LOBSTER_REGULAR));
openSansLight.setTypeface(Typeface.createFromAsset(getAssets(), OPENSANS_LIGHT));
pacifico.setTypeface(Typeface.createFromAsset(getAssets(), PACIFICO));
robotoBlack.setTypeface(Typeface.createFromAsset(getAssets(), ROBOTO_BLACK));
}
}
|
Comments
Post a Comment