2012-11-23 80 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; 
     } 
    });