Dialog with transparent background in Android

前端 未结 20 2753
孤城傲影
孤城傲影 2020-11-22 15:02

How do I remove the black background from a dialog box in Android. The pic shows the problem.

\"enter

20条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 15:34

    Attention : Don't use builder for changing background.

    Dialog dialog = new Dialog.Builder(MainActivity.this)
                                    .setView(view)
                                    .create();
    dialog.show();dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    

    change to

    Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(view);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();
    

    When using Dialog.builder, it's not giving getWindow() option in it.

提交回复
热议问题