80,348
社区成员
发帖
与我相关
我的任务
分享
public class StartPopWindow extends PopupWindow {
Button btn_start = null;
private View conentView;
Context context;
public StartPopWindow(final Activity context) {
this.context = context;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
conentView = inflater.inflate(R.layout.activity_popupwindow_start, null);
int h = context.getWindowManager().getDefaultDisplay().getHeight();
int w = context.getWindowManager().getDefaultDisplay().getWidth();
btn_start = (Button) conentView.findViewById(R.id.btn_start);
// 设置SelectPicPopupWindow的View
this.setContentView(conentView);
// 设置SelectPicPopupWindow弹出窗体的宽
this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
// 设置SelectPicPopupWindow弹出窗体的高
this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
// 设置SelectPicPopupWindow弹出窗体可点击
this.setFocusable(false);
this.setOutsideTouchable(false);
// 刷新状态
// this.update();
// 实例化一个ColorDrawable颜色为半透明
//ColorDrawable dw = new ColorDrawable(0000000000);
// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
this.setBackgroundDrawable(new BitmapDrawable());
// mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
// 设置SelectPicPopupWindow弹出窗体动画效果
this.setAnimationStyle(R.style.AnimationPreview);
}
public void showPopupWindow(final View parent) {
if (!this.isShowing()) {
int[] location = new int[2];
parent.getLocationOnScreen(location);
this.showAtLocation(parent, Gravity.NO_GRAVITY, location[0] + parent.getWidth(), location[1]);
btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
HouseNumberPopWindow houseNumberPopWindow = new HouseNumberPopWindow((Activity) context);
houseNumberPopWindow.showPopupWindow(parent);
Toast.makeText(conentView.getContext(), "1111", Toast.LENGTH_SHORT).show();
}
});
} else {
this.dismiss();
}
}
}
StartPopWindow startPopWindow = new StartPopWindow(UserLoginActivity.this);
startPopWindow.showPopupWindow(btn_regist);