创建对话框方法dialog
protected void dialog() {
View popuviewView=View.inflate(this, R.layout.out_popup, null);
View popuone=popuviewView.findViewById(R.id.one);
final LinearLayout outLayout=(LinearLayout) popuviewView.findViewById(R.id.out);
final PopupWindow popupWindow=new PopupWindow(popuviewView,ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//取消退出(关闭对话框)
popup_qx=(Button) popuviewView.findViewById(R.id.pop_quxiao);
popup_qx.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
popup_x=(ImageView) popuviewView.findViewById(R.id.out_popup_x);
popup_x.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
//确认退出(退出登录)
popup_qd=(Button) popuviewView.findViewById(R.id.pop_queding);
popup_qd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplication(), "quedeing", Toast.LENGTH_SHORT).show();
Intent loginIntent=new Intent(getApplication(), LoginActivity.class);
startActivity(loginIntent);
popupWindow.dismiss();
/**
* 通过广播(BroadcastReceiver)注销登录
* 1.点击退出按钮向MianActivity发送广播
* 2.关闭当前的acticity;
*/
Intent mainIntent=new Intent();
mainIntent.setAction("com.anxun.bqbh.activity");//添加action属性
mainIntent.putExtra("bqbh", "finish");
sendBroadcast(mainIntent);//发送消息(接收方在MianActivity到登录界面)
SetActivity.this.finish();//关闭Setactivity
}
});
// popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));
ColorDrawable dw = new ColorDrawable(-00000);
popupWindow.setBackgroundDrawable(dw);
popuone.setFocusable(true);
popupWindow.setOutsideTouchable(false);
popupWindow.showAtLocation(setLayout, Gravity.CENTER, 0, 0);
// popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
popuone.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//按下
if (event.getAction()==MotionEvent.ACTION_DOWN) {
outLayout.setEnabled(false);//不可激活
Toast.makeText(getApplication(), "按下", Toast.LENGTH_SHORT).show();
}
//抬起
if (event.getAction()==MotionEvent.ACTION_UP) {
outLayout.setEnabled(true);//可激活
Toast.makeText(getApplication(), "抬起", Toast.LENGTH_SHORT).show();
}
return true;
}
});
outLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
}