0

我在我的应用程序中添加了主菜单,我需要将菜单文本居中对齐。它在姜饼中工作正常。但它在冰淇淋三明治中左对齐。我该如何解决这个问题?

这是我的菜单布局

<?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

4

1 回答 1

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;
        }
    });
于 2012-11-23T11:21:08.937 回答