更改选项菜单标题颜色

时间:2013-11-21 06:07:20

标签: android android-layout

这是我当前的输出

enter image description here

现在

我们如何更改选项菜单标题颜色?

1 个答案:

答案 0 :(得分:1)

为菜单选项创建Actionview,您可以更改其背景

@Override
public boolean onCreateOptionsMenu(Menu menu) {
            //You can add menuitems programmatically or by inflating menu
            //Here I added programatically
            //Create your own menu item layout and add it to menu
    MenuItem menuItem = menu.add(0, 0, 0, "");
    menuItem.setActionView(R.layout.menu_item1_layout);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

            //We can get the menu item layout by below line of code
            View v = menu.getItem(0).getActionView();

            //You set your own color or drawable by below line of code
            v.setBackgroundResource(R.drawable.your_own_drawable);

    return super.onCreateOptionsMenu(menu);
}