{"id":13428809,"url":"https://github.com/zawadz88/MaterialPopupMenu","last_synced_at":"2025-03-16T01:33:38.889Z","repository":{"id":38050350,"uuid":"97512779","full_name":"zawadz88/MaterialPopupMenu","owner":"zawadz88","description":"Shows Material popup menus grouped in sections \u0026 more","archived":false,"fork":false,"pushed_at":"2021-03-24T13:53:48.000Z","size":1212,"stargazers_count":645,"open_issues_count":14,"forks_count":59,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-27T06:39:08.437Z","etag":null,"topics":["android","kotlin","list-popup-window","material-design","material-menu","popup-menu","popup-window"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zawadz88.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-17T19:10:17.000Z","updated_at":"2024-09-23T16:53:18.000Z","dependencies_parsed_at":"2022-08-08T23:00:26.130Z","dependency_job_id":null,"html_url":"https://github.com/zawadz88/MaterialPopupMenu","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zawadz88%2FMaterialPopupMenu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zawadz88%2FMaterialPopupMenu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zawadz88%2FMaterialPopupMenu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zawadz88%2FMaterialPopupMenu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zawadz88","download_url":"https://codeload.github.com/zawadz88/MaterialPopupMenu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814905,"owners_count":20352037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","kotlin","list-popup-window","material-design","material-menu","popup-menu","popup-window"],"created_at":"2024-07-31T01:01:05.678Z","updated_at":"2025-03-16T01:33:38.581Z","avatar_url":"https://github.com/zawadz88.png","language":"Kotlin","funding_links":[],"categories":["Libraries","Kotlin"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src =\"./art/logo_vertical.png\" width=\"256\" /\u003e\n\u003c/p\u003e\n\n# Material Popup Menu ![GitHubActions](https://github.com/zawadz88/MaterialPopupMenu/workflows/Android%20CI/badge.svg?branch=master)\n\nThis library allows to create simple popup menus programmatically with a nice [type-safe builder syntax in Kotlin](https://kotlinlang.org/docs/reference/type-safe-builders.html). Menus can be divided into separate sections with optional headers and contain icons.\n\n\u003cimg src =\"./art/sample_sections_light.png\" width=\"360\" /\u003e\u0026nbsp;\u0026nbsp;\u003cimg src =\"./art/sample_toolbar_dark.png\" width=\"360\" /\u003e\n\n## Download (from JCenter)\n```groovy\nimplementation 'com.github.zawadz88.materialpopupmenu:material-popup-menu:4.1.0'\n```\n\n## Getting started\n\nTo create a popup menu with a single section from an anchor view:\n```kotlin\n    fun onSingleSectionWithIconsClicked(view: View) {\n        val popupMenu = popupMenu {\n            section {\n                item {\n                    label = \"Copy\"\n                    icon = R.drawable.abc_ic_menu_copy_mtrl_am_alpha //optional\n                    callback = { //optional\n                        Toast.makeText(this@LightActivity, \"Copied!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n                item {\n                    labelRes = R.string.label_paste\n                    iconDrawable = ContextCompat.getDrawable(this@LightActivity, R.drawable.abc_ic_menu_paste_mtrl_am_alpha) //optional\n                    callback = { //optional\n                        Toast.makeText(this@LightActivity, \"Text pasted!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n                item {\n                    label = \"Select all\"\n                    icon = R.drawable.abc_ic_menu_selectall_mtrl_alpha //optional\n                }\n            }\n        }\n\n        popupMenu.show(this@LightActivity, view)\n    }\n\n```\n\nTo create a popup menu with 2 sections and a section title in the second one:\n```kotlin\n    fun onSingleSectionWithIconsClicked(view: View) {\n        val popupMenu = popupMenu {\n            section {\n                item {\n                    label = \"Copy\"\n                    icon = R.drawable.abc_ic_menu_copy_mtrl_am_alpha\n                    callback = {\n                        Toast.makeText(this@LightActivity, \"Copied!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n                item {\n                    labelRes = R.string.label_paste\n                    icon = R.drawable.abc_ic_menu_paste_mtrl_am_alpha\n                    callback = {\n                        Toast.makeText(this@LightActivity, \"Text pasted!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n            }\n            section {\n                title = \"Other\"\n                item {\n                    label = \"Select all\"\n                    icon = R.drawable.abc_ic_menu_selectall_mtrl_alpha\n                }\n            }\n        }\n\n        popupMenu.show(this@LightActivity, view)\n    }\n```\n\n## Supported features\n* Showing popup menus with a builder pattern\n* Separator between popup menu sections\n* Section headers\n* Light and dark styles\n* Custom view items\n* Setting item label text color \u0026 icon color for each individual item\n* Setting custom popup background color\n* Customizing default popup style via theme attribute\n* Adding additional offsets to where the dialog should be shown\n* Keeping popup open after clicking on item\n* Dimming background behind popup\n* Customizing popup width, padding \u0026 offsets\n* Displaying an icon at the end of each item which indicates a nested submenu\n\n## Custom views\n\u003cimg src =\"./art/sample_custom_items.png\" width=\"360\" /\u003e\n\nYou can use your own layouts for displaying the items in each section alongside the default layouts provided by the library. E.g.:\n```kotlin\n    fun onCustomItemsClicked(view: View) {\n        val popupMenu = popupMenu {\n            dropdownGravity = Gravity.END\n            section {\n                item {\n                    label = \"Copy\"\n                    icon = R.drawable.abc_ic_menu_copy_mtrl_am_alpha\n                    callback = {\n                        Toast.makeText(this@LightActivity, \"Copied!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n                customItem {\n                    layoutResId = R.layout.view_custom_item_checkable\n                    viewBoundCallback = { view -\u003e\n                        val checkBox: CheckBox = view.findViewById(R.id.customItemCheckbox)\n                        checkBox.isChecked = true\n                    }\n                    callback = {\n                        Toast.makeText(this@LightActivity, \"Disabled!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n                customItem {\n                    layoutResId = R.layout.view_custom_item_large\n                }\n            }\n        }\n\n        popupMenu.show(this@LightActivity, view)\n    }\n```\n\n## Custom colors\n\u003cimg src =\"./art/sample_custom_colors.png\" width=\"360\" /\u003e\n\nTo achieve the above you need to set `labelColor` and `iconColor` on each item in a section as shown here:\n```kotlin\n    fun onCustomColorsClicked(view: View) {\n        val popupMenu = popupMenu {\n            style = R.style.Widget_MPM_Menu_Dark_CustomBackground\n            section {\n                item {\n                    label = \"Copy\"\n                    labelColor = ContextCompat.getColor(this@LightActivity, R.color.red)\n                    icon = R.drawable.abc_ic_menu_copy_mtrl_am_alpha\n                    iconColor = ContextCompat.getColor(this@LightActivity, R.color.dark_red)\n                    callback = {\n                        Toast.makeText(this@LightActivity, \"Copied!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n                item {\n                    label = \"Paste\"\n                    labelColor = ContextCompat.getColor(this@LightActivity, R.color.red)\n                    icon = R.drawable.abc_ic_menu_paste_mtrl_am_alpha\n                    iconColor = ContextCompat.getColor(this@LightActivity, R.color.dark_red)\n                    callback = {\n                        Toast.makeText(this@LightActivity, \"Text pasted!\", Toast.LENGTH_SHORT).show()\n                    }\n                }\n            }\n            section {\n                item {\n                    label = \"Share\"\n                    labelColor = ContextCompat.getColor(this@LightActivity, R.color.green)\n                    icon = R.drawable.abc_ic_menu_share_mtrl_alpha\n                    iconColor = ContextCompat.getColor(this@LightActivity, R.color.dark_green)\n                    callback = {\n                        shareUrl()\n                    }\n                }\n            }\n        }\n\n        popupMenu.show(this@LightActivity, view)\n    }\n```\n\nTo change the popup background color you need to create a custom style and pass it under `style` to the popup builder above.\nE.g. to use the primary color you could define the style like this:\n```xml\n\u003cresources\u003e\n    \u003cstyle name=\"Widget.MPM.Menu.Dark.CustomBackground\"\u003e\n        \u003citem name=\"android:colorBackground\"\u003e@color/colorPrimary\u003c/item\u003e\n    \u003c/style\u003e\n\u003c/resources\u003e\n```\n\n## Documentation\nHTML documentation of the current version of the library is available [here](https://zawadz88.github.io/MaterialPopupMenu/material-popup-menu/).\n\n## Third Party Bindings\n\n### React Native\nYou may now use this library with [React Native](https://github.com/facebook/react-native) via the module [here](https://github.com/prscX/react-native-popover-menu)\n\n## FAQ\n\n### I want to use the library but I don't know Kotlin\nKotlin is extremely easy to use if you already know Java.\nCheck out the [official documentation](https://kotlinlang.org/docs/reference/basic-syntax.html) - it's really great!\n\n### I have not migrated to AndroidX. Can I use this library?\nIf you're still using legacy Android Support libraries you can use version 2.2.0. AndroidX is supported by default since 3.0.0.\n\n### Can I use this library on Jelly Bean?\nUp to 3.4.0 minimum supported version was API 16 (Jelly Bean) so you can use that version. Since 4.0.0 minimum supported version is API 19 (Kitkat).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzawadz88%2FMaterialPopupMenu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzawadz88%2FMaterialPopupMenu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzawadz88%2FMaterialPopupMenu/lists"}