2016-01-23 104 views
2

這是我的工具欄改變溢出菜單工具欄的文字和背景顏色

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/my_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/ToolbarTheme" 
    popupTheme="@style/ToolbarStylepopuptheme" /> 

和我style.xml

<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
    <item name="android:background">@color/colorPrimary</item> 
    <item name="android:textColorPrimary">#ffffff</item> 
    <item name="actionMenuTextColor">#ffffff</item> 
</style> 

<style name="ToolbarStylepopuptheme" > 
    <item name="android:colorBackground">@android:color/darker_gray</item> 
    <item name="android:textColor">#ffff55</item> 
</style> 

我已經查了很多在互聯網上,似乎沒有爲我工作。我的應用程序支持API級別16及以上。

+1

的可能的複製[工具欄選項菜單的背景顏色(http://stackoverflow.com/questions/29095733/toolbar-options-menu-background-顏色) –

+0

如果我在xml中將popupTheme =「@ style/ToolbarStylepopuptheme」更改爲app:popupTheme =「@ style/ToolbarStylepopuptheme」文本顏色改變但背景不變化 – has19

+0

與'app:'一起使用並將父項指定給樣式'ToolbarStylepopuptheme'與上述風格相同 – Harry

回答

0

嘗試使用:

<item name="android:popupBackground">@android:color/white</item> 

,或者補充一點:parent="@android:style/Widget.PopupMenu" 和你的代碼的嘗試。

最後:

<style name="ToolbarStylepopuptheme" parent="@android:style/Widget.PopupMenu"> 

,我忘說了,是我不好!這個(應用)添加到您的工具欄

app:popupTheme="@style/ToolbarStylepopuptheme" 
+0

我試過它不工作 – has19

+0

不工作 – has19

+0

我在android 5.0上測試它,如果這可能會有區別 – has19