How to change actionbarsherlock font menu item when using custom theme for action bar?

When I use the default sherlock theme theme, I can change the font face using this method (it can be passed to TextView)

@Override public boolean onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.main, menu); getLayoutInflater().setFactory(new LayoutInflater.Factory() { public View onCreateView(String name, Context context, AttributeSet attrs) { if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView") || name.equalsIgnoreCase("TextView")) { try { LayoutInflater li = LayoutInflater.from(context); final View view = li.createView(name, null, attrs); new Handler().post(new Runnable() { public void run() { // here I can change the font! ((TextView)view).setTypeface(MY_CUSTOM_TYPE_FACE); } }); return view; } catch (InflateException e) { // Handle any inflation exception here } catch (ClassNotFoundException e) { // Handle any ClassNotFoundException here } } return null; } }); return true; } 

actiobarsherlock with default light theme

but when I use the custom theme this tool , the above solution does not work. Thus, each element is an instance of ActionMenuItemView, and I do not know how to apply a font to it.

actiobarsherlock with custom theme

+7
source share
1 answer

need to create a custom menu view

  private ActionBar setCustomView(ActionBar actionBar,String title, String subtitle,boolean isSubTitleEnable){ LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.customer_view, null); TextView tv = (TextView) v.findViewById(R.id.cust_action_bar_title); Typeface tf = Typeface.createFromAsset(this.getAssets(), "YOURFONT.ttf"); tv.setTypeface(tf); tv.setText(title); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayOptions(0, actionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(v); return actionBar; } 
0
source

All Articles