remove white background in dialogfragment

You can create style for your dialog:

<style name="DialogStyle" parent="Base.Theme.AppCompat.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>

And use it in code by method:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new Dialog(getActivity(), R.style.DialogStyle);
}

Or you can set FEATURE_NO_TITLE for your dialog only in your code as is shown in the code below:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  Dialog dialog = super.onCreateDialog(savedInstanceState);
  dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  return dialog;
}

In the onCreateView() of your DialogFragment, replace

View rootView = inflater.inflate(R.layout.dialog_select_account, container, false);

with

View rootView = inflater.inflate(R.layout.dialog_select_account, container);

Also, add this to onViewCreated():

getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);

and in the outermost LinearLayout of the XML, change

android:layout_width="fill_parent"
android:layout_height="fill_parent"

to

android:layout_height="wrap_content"
android:layout_width="wrap_content"

Try this. This should work.


I suggest you create an alert dialog with your custom UI in onCreateDialog in your DialogFragment instead. Then you can then also easily add a style to it that will remove the white background.

 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val view = activity!!.layoutInflater.inflate(R.layout.dialogfragment_my_custom_view, null)
    val builder = AlertDialog.Builder(activity!!, R.style.MyDialogTheme)
    return builder
            .setView(view)
            .create()
}

Then you can just create the "MyDialogTheme" like this:

<style name="ProgressDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:windowBackground">@color/automile_transparent</item>
</style>