4

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

我已经用谷歌搜索并找到了很多答案,但它们对我来说似乎都没有用。

我尝试的建议是在我的 onCreateOptionsMenu 中添加:

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);

但是,它并没有帮助我。

4

0 回答 0