window.setDimAmount(0f);//去掉遮罩层(全透明)
android.view.ViewGroup.LayoutParams
android.view.WindowManager.LayoutParams 二者存在微量差别,在dialog设置宽、高时应使用android.view.WindowManager.LayoutParams设置
import android.view.WindowManager.LayoutParams;
...
..
//设置dialog自适应宽度、高度 (android.view.WindowManager.LayoutParams)
Window window = this.getWindow();
window.setBackgroundDrawableResource(R.color.transparent);
LayoutParams layoutParams = window.getAttributes();
layoutParams.alpha = 0.9f;
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
window.setAttributes(layoutParams);
本文介绍了如何在Android中去掉Dialog的遮罩层,使其变为全透明。通过设置`Window.setDimAmount(0f)`可以去除遮罩,使用`WindowManager.LayoutParams`来调整Dialog的宽高、透明度和居中显示。此外,设置了Dialog的背景为透明并调整了窗口参数以达到自适应大小并居中效果。
4212

被折叠的 条评论
为什么被折叠?



