如何更改菜单(inflater)的背景颜色?
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId() == R.id.hostList) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.host_menu, menu);
}
}
,菜单为:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/test1"
android:title="@string/test1">
</item>
<item
android:id="@+id/test2"
android:title="@string/test2">
</item>
</menu>
我尝试了很多东西,但是我可以使用&#34; TextAppearanceSpan&#34;来改变文本(或文本背景)的颜色。但我需要更改所有菜单&#39;背景
答案 0 :(得分:0)
解决方案是将背景颜色更改为您的视图:
View v = inflater.inflate(R.menu.host_menu, menu);
v.setBackgroundColor(getResources.getColor(R.color.yourColor));