zawadz88 / MaterialPopupMenu

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

How to add an disabled menu entry? #33

Closed jrcacd closed 5 years ago

jrcacd commented 5 years ago

We need that some menu entries be visible, but be disabled because some users do not have sufficient permissions.

zawadz88 commented 5 years ago

Hi, how would those disabled items look and behave?

jrcacd commented 5 years ago

Perhaps have an grayed icon and not execute the callback code.

zawadz88 commented 5 years ago

So clicking on such an item would also not dismiss the popup window?

Regarding the UI of a disabled item it's possible by using an item with a custom layout. As far as the on-click behaviour is concerned, this might a bit more tricky. I'd probably try to disable the item in viewBoundCallback and see if that works.

zawadz88 commented 5 years ago

You could have the following:

val popupMenu = popupMenu {
            section {
                // ...
                customItem {
                    layoutResId = R.layout.you_disabled_item_layout
                    viewBoundCallback = { view ->
                        view.isEnabled = false
                    }
                }
            }
        }

        popupMenu.show(context, view)

Adding view.isEnabled = false should be enough to disable onClick events.

jrcacd commented 5 years ago

Umm, ok, but a litle tricky