开发者

Change menu background color on android 2.3

开发者 https://www.devze.com 2023-02-23 04:19 出处:网络
How could I change menu background color? I try this but it is not work for me: <style name=\"MyTheme\" parent=\"@android:style/Theme\" >

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:itemBackgroun开发者_运维百科d">@drawable/menuitem_background</item>
</style>

Could you help me?

Also I use this :

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


Use setMenuBackground ........

0

精彩评论

暂无评论...
验证码 换一张
取 消