Android - ActionBarSherlock - Set textcolor of text in menu

前端 未结 2 1334
无人共我
无人共我 2020-12-19 11:21

I want to change white color of text to orange.

Here is a example.

\"ActionBarSherlock\"

2条回答
  •  长情又很酷
    2020-12-19 12:08

    You can change the color of the MenuItem text easily by using SpannableString instead of String.

    @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 red MenuItem");
        s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
        item.setTitle(s);
    }
    

提交回复
热议问题