Custom FragmentDialog with round corners and not 100% screen width –

Development issue/problem:

I create a custom dialog box with rounded corners and a layout that doesn’t fill the entire width of the screen (I prefer it to just enclose the content).

is my rounded_dialog.xml in the rendered folder, which is called by my Custom ThemeMetCorners as the background of the dialog. I also tried to put it in the background of the line that creates its content, but nothing works.

and this is what I call dialogue:

dialog = (CalendarDialog) fm.findFragmentByTag(FTAG);
ft = fm.beginTransaction();
as (dialog != null)
ft.remove(dialog box);
dialog box = CalendarDialog.newInstance(this);
dialog.setCancelable(true) ;

ft.add(dialog box, FTAG); box);

In the onCreate dialogue method I set the style and the subject:

public void onCreate(Bundle storedInstanceState) {

This is the method used onCreateView :

@General window
public view onCreateView(LayoutInflater inflater, container ViewGroup,
Bundle savedInstanceState) {
v = (MyCalendar)inflater.inflate(R.layout.calendar_dialog, container, true)
return v;

I also tried to add this to the onCreateDialog method, as suggested by other reactions to SO, but it didn’t work either:

@Check public dialog
onCreateDialog(StoredInstanceState Bundle)
Dialog d = super.onCreateDialog(StoredInstanceState);
LayoutParams lp=d.getWindow().getAttributes();
d.getWindow().setBackgroundDrawable(new ColorDrawable(0));
lp.flags=LayoutParams.FLAG_LAYOUT_NO_LIMITS | LayoutParams.FLAG_NOT_TOUCH_MODAL ;

back d;

So, to summarize, I want rounded corners, not 100% screen width, preferably around the content. Please, please, I need help, I’m really desperate, I’ve been trying for days!

How can I solve this problem?

Solution 1:

Dialog background: dialog_rounded_bg.xml

Dialog format: dialog_rounded.xml

Dialogue fragment :

The RoundedDialog public class extends the DialogFragment {

@PublicView surface
onCreateView(LayoutInflater inflater, container ViewGroup,
Bundle savedInstanceState) {
ViewView = inflater.inflate(R.layout.dialog_rounded, container, false);
// Set a transparent background and no title
if (getDialog() != null && getDialog().getWindow() != null) {
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
view to return;

The completed dialogue

Update : If the Window.FEATURE_NO_TITLE flag is not set, a blue line will appear at the top of the dialog box for Android devices ≤ 4.4.

Solution 2:

I just figured it out, but I don’t really like it.

I have defined the background (round_dialog.xml) for this dialog:

I then set it in my dialogue with the onCreateView method, as shown below. The rounded corners of this piece of code are not really necessary because the background is transparent, but the padding is important because the dialogue is as wide as the screen anyway, but the padding makes it seem as if it is not.

getDialog().getWindow().setBackgroundDrawableResource(R.drawable.rounded_dialog) ;

And finally, I fixed the background of the dialogue components on a different adapted pattern that makes the corners round. I have a LinearLayout with RelativeLayout at the top and TextView at the bottom, so I put @null on the parent LinearLayout and put two different custom designs for the two parts, one with rounded corners at the bottom and one with rounded corners at the top.

I think there’s a better solution, because it’s just visually correct, not fully functional, but correct enough for this case.

Solution 3:

Another possibility:

Use setStyle() in the onCreate() method to apply a style to your DialogFragment.
You can then use android:background as you have always done in the root view of your_layout.xml file.


  1. style.xml file (in the res folder) :
  2. Create the file_layout.xml in the formatting folder :

  1. Create a bg_corner_dialog.xml file in the Drawable folder :
  2. Finally, apply the style and layout to your dialog fragment:

The CustomDialogFragment public class extends DialogFragment {

public void onCreate(@Nullable Bundle savedInstanceState) {


See v = inflater.inflate(R.layout.your_layout, container, false);ButterKnife.bind(this, v);//enable user interface elements…return v;}.


I hope this helps.
The best wishes

Solution 4:

Update the 2021 answer with Kotlin and view binding –

Class InternetLostDialog : DialogFragmentation() {

Private Liaison with Latin Varnish : DialogInternet Lost-Link .

Overload the fun onCreateDialog (saveInstanceState: Bundle?): Dialog {
binding = DialogInternetLostBinding.inflate(LayoutInflater.from(context))
fall builder = AlertDialog.Builder(requireActivity())
isCancelable = false
binding.root.setOnClickListener {
fall dialog = builder.create()
return view


Solution No 5:

I think it would be much easier to create rounded corners, to make the map view as the root of your layout and add the following code to onCreateView():

Good luck!

round corners of dialog android,android rounded corners transparent background,android dialog theme rounded corners,bottomsheetdialog rounded corner,android popup menu rounded corners,bottom sheet rounded android,popup with rounded corners android,android toast rounded corners

You May Also Like