更改菜单项的工具栏中的文本背景

时间:2017-04-07 11:47:23

标签: android android-studio toolbar menuitem textcolor

如何在点击时更改菜单项的文字背景? 整个项目的高亮颜色是正确的,但似乎文本具有它自己的背景颜色。 我认为这笔交易已经在app:popupTheme中设定,但我不知道应该设置什么样的参数。

enter image description here

2 个答案:

答案 0 :(得分:0)

请使用此项并设置所需的颜色。

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.your_menu, menu);

    int positionOfMenuItem = 0; // or whatever...
    MenuItem item = menu.getItem(positionOfMenuItem);
    SpannableString s = new SpannableString("My MenuItem");
    s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
    item.setTitle(s);
}

答案 1 :(得分:0)

请检查How to change the background color of Action Bar's Option Menu in Android 4.2?

check image

和更改文字颜色:设置“android:textColor”将起作用

var baseAddress = string.Format("http://localhost:+:9000/");