1、简易popuwindow
View contentview = LayoutInflater.from(getApplicationContext()).inflate(R.layout.window_operate_morecontent, null);
TextView tv_caipiao=contentview.findViewById(R.id.window_tv_caipiaoyunshi);
TextView tv_save=contentview.findViewById(R.id.window_tv_save);
tv_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showWriteNameWindow();
pw_more.dismiss();
}
});
PopupWindow pw_more=new PopupWindow(contentview, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
pw_more.showAsDropDown(view);
2、管理:
2.1、在弹出框弹出时,设置弹出框的系统底色半透明(并非background.color)
float bgAlpha=0.6f;
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = bgAlpha; //0.0-1.0
getWindow().setAttributes(lp);
2.2、设置弹出框消失时,系统底色回复
pw_more=new PopupWindow(contentview, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
pw_more.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
float ba1=1f;
WindowManager.LayoutParams lp2 = getWindow().getAttributes();
lp2.alpha = ba1; //0.0-1.0
getWindow().setAttributes(lp2);
}
});
2.3、设置popw的弹出位置:
pw_more.showAsDropDown(findViewById(R.id.title_layout),20,450);
//以R.id.title_layout的左下角为原点,向X轴正方向偏移20个像素,Y轴方向偏移450个像素。
pw_more.showAtLocation(findViewById(R.id.title_layout),Gravity.RIGHT|Gravity.TOP,15,251);
//Gravity.TOP | Gravity.RIGHT,以屏幕右上角为原点,pw往X轴负方向偏移15个像素,往Y轴正方向偏移251个像素;如果是Gravity.BOTTOM| Gravity.LEFT,以屏幕左下角为原点,pw往X轴正方向偏移15个像素,往Y轴正方向偏移251个像素。