Shubham Bhardwaj
Shubham Bhardwaj

Reputation: 155

How to change textfont to century gothic in android

so typeface has 4 or 5 font styles, what if we need some other. I found textappearance can do that but how?

Upvotes: 0

Views: 1387

Answers (2)

Sabyasachi
Sabyasachi

Reputation: 3599

Create a folder called fonts under assets folder and place all your fonts in it. (Folder name can be anything)

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#222222" >

    <TextView
        android:id="@+id/ghost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="70dip"
        android:gravity="center"
        android:textColor="#ef0000"
        android:layout_marginTop="50dip"
        android:text="ghost" />

</LinearLayout>

SampleActivity.java

package com.example;

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

public class AndroidExternalFontsActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Font path
        String fontPath = "fonts/Face Your Fears.ttf";

        // text view label
        TextView txtGhost = (TextView) findViewById(R.id.ghost);

        // Loading Font Face
        Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);

        // Applying font
        txtGhost.setTypeface(tf);
    }
}

Upvotes: 1

Emre Tekin
Emre Tekin

Reputation: 472

First create assets folder and then create fonts folder in assets folder.

   TypeFace customTypeFace=Typeface.createFromAsset(getAssets(),"fonts/mytruetypefont.ttf");
Textview.setTypeface(typeFace);

Upvotes: 0

Related Questions