Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the font of the application title in android

I have a typeface, I want to change the font of the action-bar title in android. Is there a way to set title typeface like that?

this.setTitle(myTitle.toUpperCase()); 
this.setTypefaceofTitle(tf);

this is not a copy question, those methods on this link (How to Set a Custom Font in the ActionBar Title?) are not working. When I try them, eclipse gives that error : java.lang.noSuchMethodError

like image 244
anilbey Avatar asked Dec 02 '22 18:12

anilbey


1 Answers

Try this,

    int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
TextView actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);
Typeface robotoBoldCondensedItalic = Typeface.createFromAsset(getAssets(), "fonts/Roboto-BoldCondensedItalic.ttf");
if(actionBarTitleView != null){
    actionBarTitleView.setTypeface(robotoBoldCondensedItalic);
}

If it's toolbar means try like as below.

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_color”
app:theme="@style/ToolBarTheme" >


 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Title"
    android:layout_gravity="center"
    android:id="@+id/title_txt” />


</android.support.v7.widget.Toolbar>

Then just add any style via programmatically using below comment.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.title);

OR

Change using style. Need one info click here.

like image 50
Karthikeyan Avatar answered Dec 10 '22 11:12

Karthikeyan