final AlertDialog dialog = new AlertDialog.Builder(context)
.setMessage("message")
.create();
Window window = dialog.getWindow();
window.setGravity(Gravity.CENTER); //window.setGravity(Gravity.BOTTOM);
WindowManager.LayoutParams lp = window.getAttributes();
//lp.y=(int)(60*getResources().getDisplayMetrics().density);
lp.width = 530;
lp.height = 254;
lp.gravity = Gravity.CENTER;
// 设置背景层透明度
lp.dimAmount = 0.2f;
window.setAttributes(lp);
dialog.show();
View content = LayoutInflater.from(context).inflate(R.layout.layout_dialog_share, null);
TextView mTitle = (TextView) content.findViewById(R.id.tv_share_title);
TextView mSubTitle = (TextView) content.findViewById(R.id.tv_dialog_share_target);
mTitle.setText(title);
mSubTitle.setText(subTitle);
TextView mTvCancel = (TextView) content.findViewById(R.id.tv_share_cancel);
mTvCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
cancel();
}
});
TextView mTvConfirm = (TextView) content.findViewById(R.id.tv_share_confirm);
mTvConfirm.setText(confirmText);
mTvConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
setConfirm();
}
});
window.setContentView(content);