如何更改菜单项的颜色和放大器;尺寸编程?放大器、菜单项、如何更改、尺寸

2023-09-12 10:09:05 作者:本仙女不需要爱情

我搜索了很多在谷歌和计算器中的一个环节是如何使用的风格和主题,以更改文本的颜色,但我不知道如何在code使用。

I searched a lot in google and found in stackoverflow one link how to change color of text using styles and themes but I dont know how to use in code.

<style name="TextAppearance.Widget.IconMenu.Item" parent="@android:style/TextAppearance.Small"> 
        <item name="android:textColor">#ff0000</item> 
    </style> 

请给我片段为更好的理解。我知道如何使用Factory.In,我们可以发现视图对象来更改菜单项的背景。是否有任何工具来获取菜单项。然后我们就可以改变菜单项的颜色?

Please give me snippet for better understanding. I know how to change the background of menuItem by using Factory.In that we can find the View object. Is there any facility to get menu Item. Then we can change the color of menuItem?

推荐答案

试试这个code键更改背景和文本颜色....

try this code to change background and text color....

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.my_menu, menu);
    getLayoutInflater().setFactory(new Factory() {
    @Override
    public View onCreateView(String name, Context context,
                    AttributeSet attrs) {
                if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                try {
                    LayoutInflater f = getLayoutInflater();
                    final View view = f.createView(name, null, attrs);
                    new Handler().post(new Runnable() {
                            public void run() {
                            // set the background drawable
                                view.setBackgroundResource(R.drawable.my_ac_menu_background);

                            // set the text color
                                ((TextView) view).setTextColor(Color.WHITE);
                            }
                        });
                        return view;
                    } catch (InflateException e) {
                    } catch (ClassNotFoundException e) {
                    }
                }
                return null;
            }
        });
        return super.onCreateOptionsMenu(menu);
    }