全屏最主要的方法就是:
getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));//背景颜色一定要有,看自己需求
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);//宽高最大
下面我把我的全屏dialog小demo发一下,这个自定义的dialog是继承系统的Dialog类写的。小白一看就懂,超简单。
public class SexDialog extends Dialog {
private Button btRetry;
private View view;
public SexDialog(Context context){
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = LayoutInflater.from(getContext()).inflate(R.layout.dialog, null);//加载自定义布局
btRetry=(Button)view.findViewById(R.id.button2);
setContentView(view);
btRetry.setBackgroundColor(Color.RED);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
getWindow().setLayout(WindowManager.L