Pop-up window of Android PopupWindow (taking the common sharing interface as an example)
1. Main Code:
Statement:
private View shareView;private PopupWindow pop;
In the onCreate method:
// Introduce the window configuration file lateral view = LayoutInflater. from (this ). inflate (R. layout. jyx_activity_share, null); // create a PopupWindow object pop = new PopupWindow (lateral view, LayoutParams. MATCH_PARENT, LayoutParams. WRAP_CONTENT, false); // you need to set this parameter and click the outside to disappear pop. setBackgroundDrawable (new ColorDrawable (); // set the pop to disappear after the window is clicked. setOutsideTouchable (true); pop. setAnimationStyle (R. style. animationPreview); // set this parameter to get the focus. Otherwise, you cannot click pop. setFocusable (true); pop. setOnDismissListener (new OnDismissListener () {@ Overridepublic void onDismiss () {ShareSDK. stopSDK (ProductActivity. this );}});
In The onClick event: (one is the share button, and the other is the cancel button in the pop-up box)
case R.id.share:if (pop != null && !pop.isShowing()) {pop.showAtLocation(view.getRootView(), Gravity.BOTTOM, 0, 0);}break;case R.id.btn_cancel:if (pop != null && pop.isShowing()) {pop.dismiss();}break;
Effect: