Wednesday 9 April 2014

Change Action bar title Font Style android

CHANGE ACTION BAR TITLE FONT STYLE

Step 1)

get the resource ID of android title

int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");

Step 2)

Now
make object of text view and typecast the ID aquired above to textview object

TextView actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);

Step 3)

make the folder  named fonts in assets and copy  any fontstyle.ttf file in that folder


Typeface forte = Typeface.createFromAsset(getAssets(), "fonts/FORTE.TTF");

Step 4)
 Give changes according to your need to the text view

if(actionBarTitleView != null){
            actionBarTitleView.setTypeface(forte);
            actionBarTitleView.setTextSize(25);

        }
 
Step 5)

Now set title for Action bar

getActionBar().setTitle("SAMPLE");

it will set the tile with the fontstyle u specified with textview object

COMPLETE CODE
copy and paste

    int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
        TextView actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);
        Typeface forte = Typeface.createFromAsset(getAssets(), "fonts/FORTE.TTF");
        if(actionBarTitleView != null){
            actionBarTitleView.setTypeface(forte);
            actionBarTitleView.setTextSize(25);
        }
       
       
       getActionBar().setTitle("SAMPLE");


NOW run your app and see the changes