Touching anywhere on the screen dismisses the popup window. Whenever the button is clicked, the popup window is inflated and shown over the activity. It appears untill when you do not click on the pop-up menu text. If the space is not available then it displays it above the Anchor text. Here is the code for the main activity of our example. A PopUp menu is a type of menu that contains a menu and displays that menu below the anchor text if space is available. (The OP asks for a cancel button, but this is not necessary because the user can click anywhere on the screen to cancel it.) It will look like the following image.Īdd a layout file to res/layout that defines what the popup window will look like. It is a supplemental answer that deals with creating a popup window in general and not necessarily the specific details of the OP's problem. How to make a simple Android popup window How can I handle these two components in my Java code? Pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0) PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100,100, true) Java code LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE) To create a simple working PopupWindow, we need to do the following:
0 Comments
Leave a Reply. |