0

I developed an android application now i'm trying to add (Kulturista Bold. ttf )this custom font to it but it doesn't worked Here is my login.xml file and login.java files

<TextView
                android:id="@+id/maintitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="CREATE AN ACCOUNT?"
                android:textColor="@color/blue"
                android:textSize="25dp"
                android:layout_gravity="center"
                   android:layout_marginTop="70dp"
                android:gravity="center"/>
        <TextView
            android:id="@+id/subtitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="CLICK ON THE SIGHNUP AND REGISTER"
            android:textColor="#c4cbcf"
            android:layout_gravity="center"
            android:gravity="center"
             />

This is the activity code

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        TextView txt1 = (TextView) findViewById(R.id.maintitle);  
        Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold. ttf");  
        txt1.setTypeface(font1);  
        TextView txt2 = (TextView) findViewById(R.id.subtitle);  
        Typeface font2 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold. ttf");  
        txt2.setTypeface(font2);
    }

}
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
hesh
  • 11
  • 3

4 Answers4

1

If you have access from only assets folder then in your code just remove space from . ttf

So change it

Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf");

If you have created folder named fonts in assets folder then you have to access it by.

Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/Kulturista_Bold.ttf");
Piyush
  • 18,895
  • 5
  • 32
  • 63
0

Remove space from ". ttf"

//Space between dot(.) and ttf Kulturista_Bold. ttf
Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold. ttf"); 

Try this by removing space.

Typeface font1 = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf"); 
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
0

Try adding getContext or activityName before getAssets:

Typeface font = Typeface.createFromAsset(getContext(),"fonts/androidnation.ttf");

or

Typeface font = Typeface.createFromAsset(activityname.this.getAssets(), "fonts/androidnation.ttf");

txt1.setTypeface(font);
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
-1

Try this

Typeface typeFace = Typeface.createFromAsset(getAssets(), "Kulturista_Bold.ttf");
txt2.setTypeface(typeFace);
M D
  • 47,665
  • 9
  • 93
  • 114
Dakshesh Khatri
  • 639
  • 7
  • 12