Kotlin Android Popup MenuAndroid Popup Menu is a list menu that appears vertically to the view. The popup menu appears below the view if there is room otherwise, appears above. Touching outside to popup menu makes it disappear. Popup Menu provides actions that are related to the specific content, and it does not affect the corresponding content. The PopupMenu.OnMenuItemClickListener interface receives the menu items click events if the items don't have their click listener. Kotlin Android Popup Menu ExampleIn this example, we will add the popup menu items on a view (button). Clicking on the button shows the popup menu items on which we can perform the relevant action. Create an android project and select the Basic Activity. This activity auto-generates codes for the menu. activity_main.xmlAdd the following code in layout directory in the activity_main.xml file. This code is auto-generated while creating the Basic Activity. content_main.xmlAdd the following code in the content_main.xml file in layout directory. In this layout, we place a Button View component. strings.xmlpopup_menu.xmlCreate a menu resource file named as popup_menu.xml in the menu directory. Add the item tag which creates the menu item for the popup menu. MainActivity.ktAdd the following code in the MainActivity.kt class. In this class, we implement the PopupMenu.OnMenuItemClickListener interface which receives the menu items click events. To display the popup menu, call the PopupMenu.show() method. Output: Next Topic# |