public class SexPopWindow extends PopupWindow {
private TextView boy;
private TextView girl;
public SexPopWindow(Activity context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View content = inflater.inflate(R.layout.sex_pop, null);
initview(content);
this.setContentView(content);
//xml布局需要在外面在嵌套一层 不然布局文件不是你想要的
this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
this.setFocusable(true);
this.setOutsideTouchable(true);
this.update();//刷新状态
ColorDrawable dw = new ColorDrawable(0000000000);//半透明
this.setBackgroundDrawable(dw);// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
this.setAnimationStyle(R.style.AnimationPreview); // 设置SelectPicPopupWindow弹出窗体动画效果
}
private void initview(View v) {
boy = v.findViewById(R.id.boy);
girl = v.findViewById(R.id.girl);
boy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View pView) {
EventBean bean = new EventBean();
bean.setContent(boy.getText().toString());
EventBus.getDefault().post(bean);
SexPopWindow.this.dismiss();
}
});
girl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View pView) {
EventBean bean = new EventBean();
bean.setContent(girl.getText().toString());
EventBus.getDefault().post(bean);
SexPopWindow.this.dismiss();
}
});
}
//显示popupWindow
public void showPopupWindow(View v) {
if (!this.isShowing()) {
// this.showAtLocation(v, Gravity.BOTTOM, 0, 0); //相对于屏幕的
this.showAsDropDown(v, 0, 0); //相对于某个控件的位置
} else {
this.dismiss();
}
}
}
Android之自定义popwindow
最新推荐文章于 2023-06-17 05:00:00 发布