更改android 2.3上的菜单背景颜色

时间:2011-04-10 19:29:37

标签: android colors menu menuitem

如何更改菜单背景颜色?

我试试这个,但这对我不起作用:

<style name="MyTheme" parent="@android:style/Theme" >
    <item name="android:itemBackground">@drawable/menuitem_background</item>
</style>

你能帮帮我吗?

我也用这个:

protected void setMenuBackground(){
    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 );
                    // Kind of apply our own background
                    new Handler().post( new Runnable() {
                        public void run () {
                            view.setBackgroundResource( R.drawable.background);
                        }
                    } );
                    return view;
                }
                catch ( InflateException e ) {
                    e.printStackTrace();
                }
                catch ( ClassNotFoundException e ) {
                    e.printStackTrace();
                }
            }
            return null;
        }


    });
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.option_menu, menu);

    setMenuBackground();
    return true;

}

但是我有相同的结果没有改变

1 个答案:

答案 0 :(得分:0)

使用setMenuBackground ........