The pop-up window effect of PopupWindow implemented by Android can be used for prompting information.
As follows:
PopupWindow is a floating container that can be displayed on the current Activity. The position of PopupWindow can be changed. There are two types of PopupWindow: no offset and no offset; there are two types of reference objects: the relative position of a control (Anchor) and the relative position inside the parent container.
The PopupWindow implementation code is as follows:
Create PopupWindow
LayoutInflater mLayoutInflater = (LayoutInflater) context. getSystemService (LAYOUT_INFLATER_SERVICE); View contentView = mLayoutInflater. inflate (R. layout. pop, null) // R. layout. pop is the layout file PopupWindow pop = new PopupWindow (contentView, LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); pop. setBackgroundDrawable (new BitmapDrawable (); // specifies the pop of the PopupWindow background. setFocusable (true); // sets the focus of PopupWindow. The created PopupWindow has no focus by default.
Show PopupWindow
// Relative to a widget (lower left), no offset pop. showAsDropDown (View anchor) // relative to a control, there is an offset, xoff is the offset of the X axis, yoff is the offset of the Y axis pop. showAsDropDown (View anchor, int xoff, int yoff) // where the parent container is located, and gravity is the relative location, for example, Central Gravity. CENTER, Gravity. BOTTOM, Gravity. RIGHT | Gravity. BOTTOM right corner of BOTTOM, and the following two parameters are the offset of the x/y axis. Pop. showAtLocation (View parent, int gravity, int x, int y)
Close PopupWindow
pop.dismiss()