Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Custom Font of Android Menu Item?

I have the following Android Java and XML code. I want to change the font of Menu Items of my app. I know only that we can change the font of TextView using setTypeface but not able to find anyway for Menu Item.

JAVA Code-:

@Override public boolean onCreateOptionsMenu(Menu menu) {         MenuInflater inflater = getMenuInflater();     inflater.inflate(R.menu.main, menu);     return true; }  @Override     public boolean onOptionsItemSelected(MenuItem item) {    switch (item.getItemId()) {              case R.id.action_refresh1:                                                       Toast.makeText(this, "Item1 Selected", Toast.LENGTH_SHORT)             .show();               break;          case R.id.action_refresh2:                                                       Toast.makeText(this, "Item2 Selected", Toast.LENGTH_SHORT)             .show();                   break;          default:                   break;    } } 

XML Code-:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item     android:id="@+id/action_refresh1"     android:orderInCategory="100"     android:showAsAction="always"     android:title="Item1"/>  <item     android:id="@+id/action_refresh2"     android:orderInCategory="100"     android:showAsAction="always"     android:title="Item2"/> </menu> 

I want to change the font of two menu item , but don't know how to integrate settypface for Menu Item.

like image 591
Anshuman Pattnaik Avatar asked Feb 21 '14 18:02

Anshuman Pattnaik


People also ask

What menu can you use to change font style?

The menu for changing the font is in the Home tab near the top-left corner. Like the font size menu, hovering your mouse over each font option will change selected text so you can see a preview of what each font looks like. If you already know what font you want, you can start typing the name to skip to it in the menu.


Video Answer


1 Answers

Create Style in styles.xml

 <style name="Style_TextView">             <item name="fontFamily">@font/myriadproregular</item>  </style> 

Add Below code into android.support.design.widget.NavigationView

 app:itemTextAppearance="@style/Style_TextView" 

Note: It works for android.support.design.widget.NavigationView

like image 168
Suman Avatar answered Oct 02 '22 15:10

Suman