zawadz88 / MaterialPopupMenu

Shows Material popup menus grouped in sections & more
Apache License 2.0
646 stars 57 forks source link

IconColor changes when Popup is dismissed #70

Open rtsketo opened 4 years ago

rtsketo commented 4 years ago
popupMenu {
    style = R.style.Widget_MPM_Menu_Custom
    section { attachmentList?.forEach { item {
        iconColor = Color.WHITE
        labelColor = Color.WHITE
        iconDrawable = it.icon
        label = it.title
        callback = { intent(it.url) }
} } }
where R.style.Widget_MPM_Menu_Custom is <style name="Widget.MPM.Menu.Custom"><item name="android:colorBackground">#ffaf00</item></style>

The icons in the above example start white, but when one of them is selected or the dialog is dismissed, they turn black.

 

My solution was to repaint them on dismiss, like below.
val drawables = arrayListOf<Drawable>()
val popup = popupMenu {
    style = R.style.Widget_MPM_Menu_Custom
    dropDownVerticalOffset = toolBar.height
    section { attachmentList?.forEach { item {
        iconColor = white
        labelColor = white
        iconDrawable = it.icon
        iconDrawable?.apply { drawables.add(this) }
        label = it.title
        callback = { intent(it.url) }
    } } }
}

// Junky way to patch this bug.
popup.setOnDismissListener {
    drawables.forEach { drawable ->
        drawable.filter(white) } }

popup.show(context!!, it)