0

i have an app with toolbar and overflow menu just like this..

overflow pic

how to change the text font of toolbar overflow "Refresh", "Setting" and the other with custom font?

  • may be duplicate check this [link](http://stackoverflow.com/questions/4135699/how-to-set-a-font-for-the-options-menu) – Khizar Hayat Mar 01 '16 at 08:00
  • Possible duplicate of [Android toolbar center title and custom font](http://stackoverflow.com/questions/26533510/android-toolbar-center-title-and-custom-font) – Mr Robot Mar 01 '16 at 08:27

1 Answers1

0

Here is the answer you search for:

public boolean onCreateOptionsMenu(android.view.Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.cool_menu, menu);
    getLayoutInflater().setFactory(new Factory() {
        public View onCreateView(String name, Context context,
                AttributeSet attrs) {

            if (name.equalsIgnoreCase(
                    "com.android.internal.view.menu.IconMenuItemView")) {
                try {
                    LayoutInflater li = LayoutInflater.from(context);
                    final View view = li.createView(name, null, attrs);
                    new Handler().post(new Runnable() {
                        public void run() {
                            // set the background drawable if you want that
                            //or keep it default -- either an image, border
                            //gradient, drawable, etc.
                            view.setBackgroundResource(R.drawable.myimage);
                            ((TextView) view).setTextSize(20); 

                            // set the text color
                            Typeface face = Typeface.createFromAsset(
                                    getAssets(),"OldeEnglish.ttf");     
                            ((TextView) view).setTypeface(face);
                            ((TextView) view).setTextColor(Color.RED);
                        }
                    });
                    return view;
                } catch (InflateException e) {
                    //Handle any inflation exception here
                } catch (ClassNotFoundException e) {
                    //Handle any ClassNotFoundException here
                }
            }
            return null;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

Source: https://stackoverflow.com/a/11376591/5250273

However, if you want a simpler solution, you should check out this library: https://github.com/chrisjenx/Calligraphy

Community
  • 1
  • 1
Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73