Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTypeface(font) is not working

Tags:

android

I set typeface in run time .But it is not reflecting in my application.

package com.example.practice;

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

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Windsong.ttf");
        View customActionBar=getLayoutInflater().inflate(R.layout.activity_main, null);
        TextView actionBarTitle=(TextView)customActionBar.findViewById(R.id.helloworld);
        actionBarTitle.setTypeface(font); 
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

I am Expecting the following font.

enter image description here

But i am getting the following output.

enter image description here

like image 745
saravanan Avatar asked Jul 30 '26 05:07

saravanan


1 Answers

Try this.

TextView actionBarTitle=(TextView)findViewById(R.id.helloworld);   
actionBarTitle.setText("HelloWorld");
actionBarTitle.setTypeface(font); 
like image 158
Gowri Avatar answered Aug 01 '26 18:08

Gowri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!