Android 手动设置选项菜单面板的背景色

Android 手动设置选项菜单面板的背景色,android,background-color,android-optionsmenu,Android,Background Color,Android Optionsmenu,我注意到在更高版本的设备中,选项菜单的背景色默认设置为黑色。我需要将其更改为白色,以及将文本颜色更改为黑色 我在谷歌上搜索了一下,找到了很多答案,但似乎没有一个对我有用 我尝试的建议是在我的OnCreateOptions菜单中添加以下内容: getLayoutInflater().setFactory(new Factory() { @Override public View onCreateView(String name, Context context, AttributeSet attr

我注意到在更高版本的设备中,选项菜单的背景色默认设置为黑色。我需要将其更改为白色,以及将文本颜色更改为黑色

我在谷歌上搜索了一下,找到了很多答案,但似乎没有一个对我有用

我尝试的建议是在我的OnCreateOptions菜单中添加以下内容:

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     .setBackgroundColor(Color.BLACK);

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

但是,这对我没有帮助。

我在stackoverflow中搜索,我想我找到了与你的问题相匹配的答案。请浏览此链接一次。。。