0
我在android应用中使用上下文菜单来提示用户选择过滤器。相关的代码是:如何指定上下文菜单的背景颜色
TextView someView = (TextView) findViewById(id.some_view);
registerForContextMenu(someView);
...
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Select a Filter");
menu.add(0, 0, 0, "Filter1");
menu.add(0, 1, 1, "Filter2");
menu.add(0, 2, 2, "Filter3");
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
if (item.getItemId() == 0)
{
...
}
else
{
...
}
return true;
}
在styles.xml文件我用的线:
<item name="android:itemBackground">@color/someColor</item>
设置option Menu
项的背景颜色。我希望它们具有与Actionbar
相同的颜色。但效果是,context Menu
也采用相同的颜色。
我的问题是我如何为context Menu
的Menu
项目或整个上下文菜单指定背景颜色。有没有办法单独设置它?我是否可以在不影响context Menu
的情况下以其他方式设置option Menu
项目的背景颜色?