在Android 2.3更改菜单背景颜色 [英] Change menu background color on android 2.3

查看:145
本文介绍了在Android 2.3更改菜单背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何改变菜单的背景颜色?

How could I change menu background color?

我尝试这一点,但它不是为我工作:

I try this but it is not work for me:

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

}

但我有同样的结果没有什么变化。

But I have the same result Nothing change

推荐答案

使用setMenuBackground ........

Use setMenuBackground ........

这篇关于在Android 2.3更改菜单背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆