2012-10-06 19 views
7

Cuando estoy utilizando el tema de la luz Sherlock defecto que puede cambiar el tipo de fuente a través de este método (que se puede convertir en TextView)cómo cambiar la barra de herramientas de elemento de menú de barra de acciones cuando usa un tema personalizado para la barra de acciones?

@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

pero cuando se utiliza tema personalizado con this tool, lo anterior la solución no funciona De esta forma, cada elemento es una instancia de ActionMenuItemView y no sé cómo aplicarle font face.

actiobarsherlock with custom theme

+1

¿Ha encontrado una solución a esto? Tengo un problema similar. – Philio

Respuesta

0

necesidad de crear una vista de menú personalizado

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; 
} 
Cuestiones relacionadas