2017-04-07 141 views
0

如何在點擊菜單項時改變菜單項的文本背景? 在整個項目上的higlight顏色是正確的,但似乎文本有它自己的背景顏色。 我認爲這筆交易是在app:popupTheme中設置的,但我不知道應該設置什麼樣式參數。在工具欄中更改菜單項的文本背景

enter image description here

回答

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

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

check image

和改變文本顏色:設定「機器人:文字顏色」將工作

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar"> 
     ... 
     <!--This would set the menu item color--> 
     <item name="android:textColor">#000</item> 
     ... 
</style> 
+0

它不工作。當整個項目的高亮顏色是灰色時,文本顏色會發生變化,但文本背景的顏色仍然是白色(它必須是灰色的)。 – user3352926

+0

plz通過鏈接我已經提供了答案@ user3352926 –

+0

沒有這工作@ user3352926 –

相關問題