Popupwindow shows that other backgrounds are dimmed. Plus Click events ~ (for logging)

Source: Internet
Author: User


public class Mainactivity extends Activity implements Onclicklistener {

protected int mscreenwidth;
protected int mscreenheight;
Private Popupwindow Popupwindow;
Private button button;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);

Button = (button) Findviewbyid (R.id.button1);
Button.setonclicklistener (this);

Gets the current screen width height
Displaymetrics metric = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Metric);
Mscreenwidth = Metric.widthpixels;
Mscreenheight = Metric.heightpixels;
}


@Override
public void OnClick (View v) {

Switch (V.getid ()) {
Case R.id.button1:
if (Popupwindow! = null&&popupwindow.isshowing ()) {
Popupwindow.dismiss ();
Return
} else {
Initmpopupwindowview ();
Popupwindow.showasdropdown (V, 0, 5);
}
Break
Default
Break
}
}

public void Initmpopupwindowview () {
Get your own view of defining layout file Pop.xml
View CustomView = Getlayoutinflater (). Inflate (R.layout.popview_item,
NULL, FALSE);
Create a Popupwindow instance, which is width and height
Popupwindow = new Popupwindow (CustomView, Mscreenwidth, 600);
Popupwindow.setanimationstyle (R.style.animationfade);

Windowmanager.layoutparams params= GetWindow (). GetAttributes ();
params.alpha=0.5f;
GetWindow (). SetAttributes (params);

Popupwindow.setoutsidetouchable (TRUE);
Popupwindow.setfocusable (TRUE);
Popupwindow.settouchable (TRUE);

// Popupwindow.setbackgrounddrawable (New bitmapdrawable ());
Define your own view Join Touch event
Customview.setontouchlistener (New Ontouchlistener () {


@Override
public boolean OnTouch (View V, motionevent event) {
Closepopupwindow ();
System.out.println ("44444444444444444444");
return false;
}
});


/** the ability to define your own view here */
Button Btton2 = (button) Customview.findviewbyid (R.id.button2);
Button Btton3 = (button) Customview.findviewbyid (R.id.button3);
Btton2.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
Intent Intent2 = new Intent (mainactivity.this,a.class);
StartActivity (Intent2);
Popupwindow.dismiss ();
}
});
Btton3.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
Intent Intent3 = new Intent (mainactivity.this,b.class);
StartActivity (INTENT3);
Popupwindow.dismiss ();
}
});
}
/**
* Close Form
*/
private void Closepopupwindow ()
{
if (Popupwindow! = null && popupwindow.isshowing ()) {

Popupwindow.dismiss ();
Popupwindow = null;
Windowmanager.layoutparams params= GetWindow (). GetAttributes ();
params.alpha=1.0f;
GetWindow (). SetAttributes (params);

}
}

}

Figure 1:

Figure 2:


Layout file: Activity_mian.xml

<linearlayout
Android:id= "@+id/a_c"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:background= "#C0C0C0"
>
<button
Android:id= "@+id/button1"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:layout_alignparentleft= "true"
Android:layout_alignparenttop= "true"
android:gravity= "Center"
android:text= "Click Drop-down list"/>
</LinearLayout>

There is also an XML. Just two buttons, nothing to put on.

http://download.csdn.net/detail/u012062810/8897455

When you click Popwindow, the Click Drop down list (1) will also darken.

There are small partners to solve this method, I hope a little pointing down ~ Thank you.


Popupwindow shows that other backgrounds are dimmed. Plus Click events ~ (for logging)

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.