Cong Wu
Cong Wu

Reputation: 482

how to dismiss a popupwindow when click button?

it think it because it tirgger the outside and clicklistener

Upvotes: 0

Views: 1447

Answers (4)

Jeffalee
Jeffalee

Reputation: 1085

To make the popup dissapear when clicked on the outside use:

   myPopupWindow.setOutsideTouchable(true);

To open and close the popup on clicking the button, put this code in your OnClickListener:

    if(myPopupWindow.isShowing()) {
        myPopupWindow.dismiss();
    } else {
        mPopupWindow.setContentView(brushView);
        mPopupWindow.showAsDropDown(v);
    }

Upvotes: 1

Cong Wu
Cong Wu

Reputation: 482

just find a trick use

        mPopupWindow=new PopupWindow(new View(mcontext),WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT,true);

i don't know why but it works

Upvotes: 0

Rajan Bhavsar
Rajan Bhavsar

Reputation: 1857

Please try with below answer:

mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); 
mPopupWindow.setOutsideTouchable(true); 

Upvotes: 1

pavel
pavel

Reputation: 1671

Just use

   myPopupWindow.setOutsideTouchable(true);

Upvotes: 0

Related Questions