我想创建左边距和上边距的自定义对话框。
我试过这个
final Dialog dialog = new Dialog(Home.this);
dialog.getWindow().getAttributes().gravity = Gravity.LEFT|Gravity.TOP;
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));
dialog.setContentView(R.layout.home_menu);
dialog.show();
它对齐布局左侧和顶部。它很好但我需要边距或填充它们。如果任何人都知道这个,请告诉我如何实现这一点。谢谢提前。< / p>
答案 0 :(得分:0)
试试这个:
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
window.setGravity(Gravity.LEFT | Gravity.TOP);
dialog.getWindow().getAttributes().verticalMargin=0.01F;
dialog.getWindow().getAttributes().horizontalMargin=0.01F;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
dialog.show();