Custom Popupwindow Popup Background gray State

Source: Internet
Author: User
Tags set background

Recently have done fragment in the definition of Popupwindow,

Fragment Inside Call:

Click the plus button
@Click
protected void Ll_add_pharmacy () {

Mpoptemplist.showasdropdown (ll_add_pharmacy, 0, getactivity ()); Passed to Popupwindow getactivity ();

Mpoptemplist.setonclicklistener (New Onokclicklistener () {

@Override
public void Onokclick (int which) {
Switch (which) {
Case 1://Add Medicine
Intent Intent = new Intent ();
ONEALLBACTH represents single item or bulk add logo 1
Intent.putextra ("Oneallbacth", "1");
Intent.setclass (Getactivity (), Annotationclassutil.get (Addnewpharmacyactivity1.class));
Getactivity (). Startactivityforresult (Intent, Mainactivity.connect_gun);
Break

}
}
});
}

Custom Popupwindow:

Package com.hospital.widget;

Import android.app.Activity;
Import Android.content.Context;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup.LayoutParams;
Import Android.view.WindowManager;
Import Android.widget.ImageView;
Import Android.widget.PopupWindow;
Import Android.widget.PopupWindow.OnDismissListener;
Import Android.widget.TextView;

Import COM.HOSPITAL.R;

/**
*
* @ClassName: Popselectpharmacy
* @Description: TODO
* @author WUC
*
*/
public class Popselectpharmacy implements view.onclicklistener{

/**
* int which
* 1. Add medicine 2. Stock Alert 3. Search for drugs
* @author Achen
*
*/
public static interface Onokclicklistener {
public void Onokclick (int which);
}

Life Interface Object
Private Onokclicklistener Mclicklistener;

Setting up the listener is the instantiation of the interface
public void Setonclicklistener (final Onokclicklistener Clicklistener) {
This.mclicklistener = Clicklistener;
}

Private context context;
Private Popupwindow Popupwindow;
Private TextView Tv_adddrug, Tv_storageremind, Tv_searchdrug;
Private Layoutinflater Inflater;
Private ImageView Iv_yfgl_addxiaohongdiankucun;

Public ImageView Getiv_yfgl_addxiaohongdiankucun () {
return iv_yfgl_addxiaohongdiankucun;
}

public void Setiv_yfgl_addxiaohongdiankucun (
ImageView Iv_yfgl_addxiaohongdiankucun) {
This.iv_yfgl_addxiaohongdiankucun = Iv_yfgl_addxiaohongdiankucun;
}

Public Popselectpharmacy (Final context context) {
This.context = context;

Inflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service);
View view = Inflater.inflate (r.layout.pop_selectpharmacy, NULL);

Tv_adddrug = (TextView) View.findviewbyid (R.id.tv_adddrug);
Tv_storageremind = (TextView) View.findviewbyid (R.id.tv_storageremind);
Tv_searchdrug = (TextView) View.findviewbyid (R.id.tv_searchdrug);
Iv_yfgl_addxiaohongdiankucun = (ImageView) View.findviewbyid (R.id.iv_yfgl_addxiaohongdiankucun);

Tv_adddrug.setonclicklistener (this);
Tv_storageremind.setonclicklistener (this);
Tv_searchdrug.setonclicklistener (this);

Popupwindow = new Popupwindow (view, layoutparams.wrap_content, layoutparams.wrap_content);
This is to make it disappear by clicking "Go Back" and will not affect your background (very magical)
Popupwindow.setbackgrounddrawable (context.getresources). Getdrawable (R.drawable.add_drugbackground));

}

Drop-down pop-up menu parent lower right corner
public void Showasdropdown (View parent, String key, activity activity) {
Showasdropdown (parent, 0, activity);
}

Private View parent;
/**
* To resolve a bug that padding invalid after setting the background
* @param Parent
* @param key
* @param padding
*/
public void Showasdropdown (View parent, int[] padding) {

This.parent = parent;
Popupwindow.showasdropdown (parent, 0, Context.getresources (). Getdimensionpixelsize (R.dimen.popmenu_yoff));
Popupwindow.setbackgrounddrawable (Context.getresources (). getdrawable (R.drawable.add_drugbackground));
Parent.setpadding (Padding[0], padding[1], padding[2], padding[3]);
Popupwindow.setondismisslistener (New Ondismisslistener () {

@Override
public void Ondismiss () {

}
});
Bring it Together
Popupwindow.setfocusable (TRUE);
Settings allow outside clicks to disappear
Popupwindow.setoutsidetouchable (TRUE);
Refresh Status
Popupwindow.update ();
}

public void Showasdropdown (View parent, int padding, final activity activity) {
This.parent=parent;
Int[] paddings = {padding, padding, padding, padding};
Showasdropdown (parent, paddings);

Set Background color dimmed
Windowmanager.layoutparams LP = Activity.getwindow (). GetAttributes ();
Lp.alpha = 0.7f;
Activity.getwindow (). SetAttributes (LP);
Popupwindow.setondismisslistener (New Ondismisslistener () {

@Override
public void Ondismiss () {
Windowmanager.layoutparams LP = Activity.getwindow (). GetAttributes ();
Lp.alpha = 1f;
Activity.getwindow (). SetAttributes (LP);
}
});
}

public void Dismisspop () {
if (parent!=null)
Popupwindow.dismiss ();
}

Public Popupwindow Getpopupwindow () {
return Popupwindow;
}

@Override
public void OnClick (final View v) {
TODO auto-generated Method Stub
Final int id = V.getid ();
Switch (ID) {
Case R.id.tv_adddrug:
if (This.mclicklistener! = null) {
This.mClickListener.onOKClick (1);
Popupwindow.dismiss ();
}
Break
Case R.id.tv_storageremind:
if (This.mclicklistener! = null) {
This.mClickListener.onOKClick (2);
Popupwindow.dismiss ();
}
Break
Case R.id.tv_searchdrug:
if (This.mclicklistener! = null) {
This.mClickListener.onOKClick (3);
Popupwindow.dismiss ();
}
Break
}
}
}

Custom Popupwindow Popup Background gray State

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.