Change default popup menu submenu arrow

Viewed 946

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?

2 Answers

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>

custom theme and set listMenuViewStyle

<style name="AppTheme" parent="Theme.MaterialComponents.Light">
    <item name="listMenuViewStyle">@style/listMenuViewStyle</item>
</style>

set subMenuArrow

<style name="listMenuViewStyle" parent="Base.Widget.AppCompat.ListMenuView">
    <item name="subMenuArrow">@drawable/icon_sub_menu</item>
</style>

apply custom theme to activity

<activity android:name=".material.MyTopAppBarActivity"
    android:theme="@style/AppTheme"/>
Related