全屏Popupwindow的实现方法

//创建popupwindow

PopupWindow   popupWindow =new PopupWindow();

//设置宽高属性为充满全屏

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.必须设置背景色否则无法实现

popupWindow.setBackgroundDrawable(new ColorDrawable());

//setOutsideTouchable方法设置为true表示可以点击

popupWindow.setOutsideTouchable(true);

//设置按钮点击事件

button.setOnClickListener(new View.OnClickListener() {

@Override

    public void onClick(View v) {

//点击按钮调用dismiss()方法关闭popupwindow

        popupWindow.dismiss();

}

});

你可能感兴趣的:(全屏Popupwindow的实现方法)