There are two types of Android dialogs: PopupWindow and AlertDialog. Their differences are:
The position of AlertDialog is fixed, while the position of PopupWindow can be random.
AlertDialog is a non-blocking thread, while PopupWindow is a blocking thread.
The position of PopupWindow can be divided into two types: Offset and no offset based on whether there is any offset. According to the difference of the reference object, it can be divided into a control (Anchor) and a parent control. The details are as follows:
ShowAsDropDown (View anchor): relative to a control (lower left), no offset
ShowAsDropDown (View anchor, int xoff, int yoff): The position of a widget with an offset.
ShowAtLocation (View parent, int gravity, int x, int y): The position relative to the parent control (for example, central Gravity. CENTER. Gravity. BOTTOM, etc.), you can set an offset or no offset
Code
[Java]
LayoutInflater inflater = (LayoutInflater) DeliveryActivity. this. getSystemService (LAYOUT_INFLATER_SERVICE );
View view = inflater. inflate (R. layout. popup_sms, null );
LinearLayout popup_contact = (LinearLayout) view. findViewById (R. id. popup_contact );
LinearLayout popup_input = (LinearLayout) view. findViewById (R. id. popup_input );
Popup_contact.setOnClickListener (DeliveryActivity. this );
Popup_input.setOnClickListener (DeliveryActivity. this );
SelectSMSPopup = new PopupWindow (view );
SelectSMSPopup. setWidth (WindowManager. LayoutParams. WRAP_CONTENT );
SelectSMSPopup. setHeight (WindowManager. LayoutParams. WRAP_CONTENT );
// It must be set. Otherwise, no response is returned when you click elsewhere on the page.
SelectSMSPopup. setBackgroundDrawable (new BitmapDrawable ());
// Set the focus, which must be set; otherwise, the listView cannot respond.
SelectSMSPopup. setFocusable (true );
// Set the position to disappear when you click somewhere else
SelectSMSPopup. setOutsideTouchable (true );
// Display at a certain position
SelectSMSPopup. showAsDropDown (LinearLayout