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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With