2012-11-23 44 views
0

我在我的应用程序中添加了主菜单,我需要菜单文本为中心align.it在姜面包中的工作状态良好,但它在冰淇淋三明治中保持对齐。我可以解决这个问题吗?ICS中的Android主菜单

这是我的菜单布局

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:id="@+id/menu_home" 
     android:title="@string/home" 

     /> 
</menu> 

截图:

img http://img594.imageshack.us/img594/5756/device20121123152830.png

+0

你可以张贴截图? – dumbfingers

+0

对不起,我没有权限在这里添加图片。 – user1688181

+0

你可以将截图上传到图片网站,然后在这里发布链接。 – dumbfingers

回答

0
 getLayoutInflater().setFactory(new Factory() { 

     @Override 
     public View onCreateView (String name, Context context, AttributeSet attrs) { 

      if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) { 

       try { // Ask our inflater to create the view 
        LayoutInflater f = getLayoutInflater(); 
        final View view = f.createView(name, null, attrs); 
        /* 
        * The background gets refreshed each time a new item is added the options menu. 
        * So each time Android applies the default background we need to set our own 
        * background. This is done using a thread giving the background change as runnable 
        * object 
        */ 
        new Handler().post(new Runnable() { 
         public void run() { 
          view.setBackgroundResource(R.drawable.bg_btn1); 
          view.setPadding(left, top, right, bottom); 
         } 
        }); 
        return view; 
       } 
       catch (InflateException e) {} 
       catch (ClassNotFoundException e) {} 
      } 
      return null; 
     } 
    });