google front support in android

Font Style For Android

Font Style For Android

In this tutorial we are going to learn how support google font in android. In asserts folder we take .ttf file. We have taken here eight different font file to show different style in font in TextView.

 

Short Code:-

Typeface SCRIPTIN = Typeface.createFromAsset(getAssets(), "fonts/SCRIPTIN.ttf");
 text_view.setTypeface(SCRIPTIN );

 

Source Code:-

FontSupportActivity.java


 

package com.androidfromhome.fontsupport;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class FontSupportActivity extends Activity {

    private TextView tv_one;
    private TextView tv_two;
    private TextView tv_three;
    private TextView tv_four;
    private TextView tv_five;
    private TextView tv_six;
    private TextView tv_seven;
    private TextView tv_eight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_font_support);
        
        Typeface BLKCHCRY = Typeface.createFromAsset(getAssets(), "fonts/BLKCHCRY.TTF");
        Typeface CarnevaleeFreakshow = Typeface.createFromAsset(getAssets(), "fonts/Carnevalee Freakshow.ttf");
        Typeface CAROBTN = Typeface.createFromAsset(getAssets(), "fonts/CAROBTN_.TTF");
        Typeface Eutemia = Typeface.createFromAsset(getAssets(), "fonts/Eutemia.ttf");
        Typeface GypsyCurse = Typeface.createFromAsset(getAssets(), "fonts/Gypsy Curse.ttf");
        Typeface HOMOARAK = Typeface.createFromAsset(getAssets(), "fonts/HOMOARAK.TTF");
        Typeface Precious = Typeface.createFromAsset(getAssets(), "fonts/Precious.ttf");
        Typeface SCRIPTIN = Typeface.createFromAsset(getAssets(), "fonts/SCRIPTIN.ttf");
        
        tv_one=(TextView)findViewById(R.id.tv_one);
        tv_two=(TextView)findViewById(R.id.tv_two);
        tv_three=(TextView)findViewById(R.id.tv_three);
        tv_four=(TextView)findViewById(R.id.tv_four);
        tv_five=(TextView)findViewById(R.id.tv_five);
        tv_six=(TextView)findViewById(R.id.tv_six);
        tv_seven=(TextView)findViewById(R.id.tv_seven);
        tv_eight=(TextView)findViewById(R.id.tv_eight);
        
        
        tv_one.setTypeface(BLKCHCRY);
        tv_two.setTypeface(CarnevaleeFreakshow);
        tv_three.setTypeface(CAROBTN);
        tv_four.setTypeface(Eutemia);
        tv_five.setTypeface(GypsyCurse);
        tv_six.setTypeface(HOMOARAK);
        tv_seven.setTypeface(Precious);
        tv_eight.setTypeface(SCRIPTIN);
        
            
    }

    
}

 

 


 

activity_font_support.xml


 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#343434"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="4dp"
        android:background="#A758AB"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="15dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:text="Android From Home"
            android:textColor="#ffffff"
            android:textSize="22dp"
            android:textStyle="bold" />
    </LinearLayout>

    <TextView
        android:id="@+id/tv_one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_two"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_three"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_four"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_five"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_six"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_seven"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    
    <TextView
        android:id="@+id/tv_eight"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    

</LinearLayout>

 


 

Download Full Source Code

 

Related Post:-

Android Autostart App

Sqlite database example in android

GridView example in android with Custom layout

ListView With section header in android example

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Widget