Search code examples
androidxmlpopuppopupmenu

Change default popup menu submenu arrow


I'm using default PopupMenu. I've customized it in my XML style, and now it has a dark style. but I have a problem now: please look at this screenShot I've prepared:

enter image description here

As you can see the arrow is kind of hard to see and I really wish to avoid using popup window now. Is there any way that I could change it to a white arrow?


Solution

  • It's been a long time, but in case anyone else runs into this problem, you can leverage a style to fix this.

    it looks like the color of the arrow is controlled by android:textColorSecondary, so if you are programmatically generating a popup menu, you could do something like this (in Kotlin):

    val contextThemeWrapper = ContextThemeWrapper(context, R.style.PopupMenuStyle)
    val popupMenu = PopupMenu(contextThemeWrapper, view)
    val menu = popupMenu.menu
    menu.addSubMenu(groupId, itemId, order, groupTitle)
    menu.add(groupId, itemId, order, title1)
    menu.add(groupId, itemId, order, title2)
    etc...
    

    and define your PopupMenuStyle like this in your styles.xml:

    <style name="PopupMenuStyle" parent="@style/<some.parent.style>">
        <!--this makes an the arrow for a menu's submenu white-->
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>