Pop-up window of Android PopupWindow (taking the common sharing interface as an example)

Source: Internet
Author: User

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:




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.