Use of Android Popupwindow

Source: Internet
Author: User

1. Set the Popupwindow background to 60% Transparent

window window = Activity.getwindow ();

Windowmanager.layoutparams LP = Window.getattributes ();

Lp.alpha = 0.6f;

Window.setattributes (LP);

Remember to hide the popupwindow when you need to recover

Windowmanager.layoutparams LP = Window.getattributes ();

lp.alpha = 1f;

window.setattributes (LP);

2. Problems with positioning

2.1 Get custom view's Wide height * * *

View.measure (Layoutparams.wrap_content, layoutparams.wrap_content);

int viewwidth = View.getmeasuredwidth ();

int viewheight = View.getmeasuredheight ();

2.2 The position of the Popupwindow relative Guideview can be calculated based on the width of the loaded view.

Popwindow.showasdropdown (Guideview, location[0], location[1]);

or position relative to the entire screen:

Popwindow.showatlocation (parent, gravity.center, 0, 0);

3. Do not add popwindow.setbackgrounddrawable (New bitmapdrawable ()); Popwondow does not respond to return key events and click Out-of-zone events.

4. After the Popupwindow appears, the default is that all operations are not valid except the home key. And you can manipulate the back.

interface. To lock the back of the interface, it's simple, just let Popupwindow be focusable.

Popupwindow.setfocusable (TRUE);

5. Get events outside of the click Area

popwindow.setfocusable (true);

popwindow.settouchable (true);

Popwindow.settouchinterceptor (New Ontouchlistener () {

@Override

Public boolean OnTouch (View V, motionevent event) {

if (popwindow.isshow ()) {

Show Popwindow

return true;

}

return false;

        }

    });


This article is from the "Sheep" blog, please make sure to keep this source http://5934497.blog.51cto.com/5924497/1617937

Use of Android Popupwindow

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.