Shreyash Mahajan
Shreyash Mahajan

Reputation: 23606

Problem in how to integrate font for android Application

I want to set the font for my application. The font is like "JOURNAL". But the problem is, i don't know how to integrate it in to myapplication. and if i integrate it then would it be for all the application or for only the selected application? because I want it to be set just for only one application. not for all. So for that what should i have to do ? I have seen here. but i think it is for only TextView and not for whole application font. So, Is there anything i have to do in manifest file ??? or what else i have to do ?? Please help me regarding it.

Upvotes: 0

Views: 679

Answers (2)

nahwarang
nahwarang

Reputation: 653

I agree to @Kheldar statement. There is no method to change the font in an Android app. Try this code to avoid calling a set method each time you want to change the font of an element.

public class MyTextView extends TextView {

Context context;
String ttfName;

public MyTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    for (int i = 0; i < attrs.getAttributeCount(); i++) {
        this.ttfName = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.package.my", "ttf_name");

        init();
    }
}

private void init() {
    Typeface font = Typeface.createFromAsset(context.getAssets(), ttfName);
    setTypeface(font);
}

@Override
public void setTypeface(Typeface tf) {
    super.setTypeface(tf);
}

}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:package="http://schemas.android.com/apk/res/com.package.my"
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/icon"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dp" />
    <com.package.my.MyTextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_toRightOf="@+id/icon"
        package:ttf_name="My-font.otf" />
</RelativeLayout>

Upvotes: 2

Kheldar
Kheldar

Reputation: 5389

You cannot modify the fonts system-wide from an application (at least, as far as I know and barring some exploit).

Study this link: http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/

Upvotes: 1

Related Questions