public static Dialog showPrivacyExpandDialog(Activity context, View viewRelative, OnClickListener mLis,int layoutId) {
Dialog mDialog = new Dialog(context, R.style.mydialog);// 创建Dialog并设置样式主题
View view = mDialog.getWindow().getLayoutInflater().inflate(layoutId, null);
mDialog.setContentView(view);
Window win = mDialog.getWindow();
win.setGravity(Gravity.RIGHT | Gravity.TOP);
WindowManager.LayoutParams lp = win.getAttributes();
//set dialog window lp
lp.width=300;//px
lp.height=300;
lp.dimAmount = 0f;/**set windows background 1.0不变暗*/
int screenWidth = context.getWindowManager().getDefaultDisplay().getWidth();
//set 偏移,相对于gravity定义的起始位置
lp.x = screenWidth - viewRelative.getRight();
lp.y = viewRelative.getBottom();
mDialog.setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域关闭Dialog
mDialog.show();
return mDialog;
}
自定义Dialog位置相对于指定控件
最新推荐文章于 2024-04-28 11:22:54 发布