//創(chuàng)建popupwindow
PopupWindow ? popupWindow =new PopupWindow();
//設(shè)置寬高屬性為充滿全屏
popupWindow.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
popupWindow.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
//得到popupwindow的布局
View inflate = View.inflate(MainActivity.this, R.layout.layout_popupwindow,null);
//獲取布局控件
Button button =(Button) inflate.findViewById(R.id.mweight_popuipwindow);
popupWindow.setContentView(inflate);
popupWindow.showAsDropDown(inflate);
//旁邊會銷毀的方法
//1.必須設(shè)置背景色否則無法實現(xiàn)
popupWindow.setBackgroundDrawable(new ColorDrawable());
//setOutsideTouchable方法設(shè)置為true表示可以點擊
popupWindow.setOutsideTouchable(true);
//設(shè)置按鈕點擊事件
button.setOnClickListener(new View.OnClickListener() {
@Override
? ? public void onClick(View v) {
//點擊按鈕調(diào)用dismiss()方法關(guān)閉popupwindow
? ? ? ? popupWindow.dismiss();
}
});