One of Android three pop-up boxes Poprpwindow

Source: Internet
Author: User

Poprpwindow

In the Android pop-up box I currently learned that there are three kinds: alertdialog,poprpwindow,activity pseudo-bullet box,

  Alertdialog is so familiar, it's not introduced here.

Let's see Poprpwindow.

The explanations given by the API are:

  

It means a pop-up form showing the view that will float on top of the current activity,

The difference between it and alertdialog is that there are two ways to pop up a box in Android: Alertdialog and Popupwindow, which are different:
1, the position of Alertdialog fixed, and the position of Popupwindow can be arbitrary;
2. Alertdialog is non-blocking thread, while Popupwindow is blocking thread

  Here's an example to illustrate the use of Popupwindow:

Activity.class:

1  Public classMainactivityextendsActivity {2 3     PrivateButton btn;4 5 @Override6     protected voidonCreate (Bundle savedinstancestate) {7         Super. OnCreate (savedinstancestate);8 Setcontentview (r.layout.activity_main);9BTN =(Button) Findviewbyid (r.id.show);TenBtn.setonclicklistener (NewButton.onclicklistener () { One              A @Override -              Public voidOnClick (View v) { -Popupwindow Popupwindow =NewPopupwindow (mainactivity. This); the                 //here is a ListView displayed in Popupwindow, you can also load a xx.xml file (Layoutfalter.from (). Inflate ()) -ListView ListView =NewListView (mainactivity. This);  -arrayadapter<string> adapter =NewArrayadapter<string> (mainactivity. ThisAndroid. R.layout.simple_dropdown_item_1line,Newstring[]{"First", "second"}); - Listview.setadapter (adapter); +Popupwindow.setcontentview (ListView);//the view to be displayed in the Popupwindow -Popupwindow.setheight (500); +Popupwindow.setwidth (180); APopupwindow.setoutsidetouchable (true);//false By default outside of the Popupwindow range atPopupwindow.setbackgrounddrawable (NewColordrawable (Color.argb (50, 52, 53, 55))); -                 /** - * Popupwindow.showasdropdown (anchor, Xoff, Yoff) is used to mark where the Popupwindow is to be displayed - * Anchor: To the view as the standard location - * Xoff: The x offset at the base position of the anchor - * Yoff: The y offset at the base position of the anchor in                  */ -Popupwindow.showasdropdown (btn, 0, 0); to                  +             } -         }); the          *     } $ Panax Notoginseng @Override -      Public BooleanOncreateoptionsmenu (Menu menu) { the getmenuinflater (). Inflate (R.menu.main, menu); +         return true; A     } the  +}

The corresponding XML file contains a button that is not posted.

Source code Download: Source code

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.