1

How do I change the background color of AppCompatDialogFragment.

My class is extends AppCompatDialogFragment and I don't know how to change the property background color of all the dialog.

public class MyClassName extends AppCompatDialogFragment { ...}
Guy Luz
  • 3,372
  • 20
  • 43

1 Answers1

1

You can use the same method posted here about making the background transparent and change transparent to color.

Create onCreateView and inside add the following line: getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));

Change Color.YELLOW to the background color that you want.

Full example:

public class ClassName extends AppCompatDialogFragment {
    ...
    ...
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
        return super.onCreateView(inflater, container, savedInstanceState);
    }
}

If you want color from colors resources use:

getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(getContext().getColor(R.color.colorPrimary)));

Were colorPrimary is color resources name.

Guy Luz
  • 3,372
  • 20
  • 43