Reputation: 202
Hey everyone I am dealing with a small problem with Popup menu. Honestly I dont know where is the problem, I tried to search the internet if I can find any answers but unfortunatelly I cant. So..
I created a custom toolbar and set the activity to no actionbar. Then I created a popUp menu in this toolbar. First I tried to change the icon of a menu via styles and it worked. But then I wanted to change the background and text color of a menu items.
This is the code I have in my design tab of the menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/fitItem1"
android:title="Item 1"
app:showAsAction="never" />
<item android:id="@+id/fitItem2"
android:title="Item 2"
app:showAsAction="never"/>
<item android:id="@+id/fitItem3"
android:title="Item 3"
app:showAsAction="never"/>
And even in the design menu it looked like this: But when you start the app it looks by default (white background, black text)
So I thought that is it set somewhere in styles but there is nothing like that and every guide I tried to follow had no effect. Except style name="MyPopBackground" which actully changes the background.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
<item name="android:itemTextAppearance">@style/MyApp.PopupMenu</item>
<item name="android:popupBackground">@style/MyPopBackground</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyActionButtonOverflow" parent="android:Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">@drawable/triple_dot_icon</item>
</style>
<style name="MyApp.PopupMenu" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/colorLightGrey</item>
</style>
<style name="MyPopBackground" parent="android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@color/colorGrey</item>
</style>
</resources>
There might be some useless styles but since I didnt know where is the prob. I left them there. My goal is to make that menu look like that one the image showed before.
I would be glad for any help, thanks for help.
Upvotes: 3
Views: 221
Reputation: 80
Add popupMenu style to your AppTheme
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
then at mainifest.xml
<application
android:theme="@style/AppTheme" >
</application>
Upvotes: 1
Reputation: 1018
In style AppTheme, You add <item name="android:itemBackground">@color/colorMenu</item>
Upvotes: 0