How to make custom dialog with rounded corners in android
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Rounded custom dialogs are common in Android for confirmations, forms, and contextual actions. The visual design is simple, but implementation often fails because only the layout is styled while the dialog window remains opaque. A reliable solution styles the background drawable, dialog window, and layout spacing together.
Create a Reusable Rounded Background Drawable
Define corners, fill color, and optional stroke in a drawable resource.
This keeps styling independent from dialog content and makes reuse easier across screens.
For dark mode, add a matching file in res/drawable-night.
Build Dialog Layout with Proper Internal Padding
Dialog content layout should focus on structure and spacing, not fake rounded corners.
Spacing inside the layout prevents content from touching rounded edges.
Apply Window Background and Insets in Kotlin
Use AlertDialog or DialogFragment, then set window background after dialog creation.
If you skip window background customization, corners may still appear square due to default frame rendering.
Use DialogFragment for Lifecycle Safety
For configuration changes and fragment based navigation, DialogFragment is more robust than plain dialog objects.
Theme example:
Fragment setup:
This approach integrates better with lifecycle and state restoration.
Handle Width and Responsiveness
Dialogs that look fine on phones can break on tablets or landscape mode. Set width dynamically after show:
Using density independent spacing and dynamic width makes design stable across device classes.
Accessibility and Testing
Rounded corners should never reduce usability. Verify:
- Text contrast in light and dark themes.
- Adequate touch target sizes.
- Behavior under large font scaling.
Use UI tests to check dialog visibility and button actions. Snapshot tests help detect visual regressions when theme changes are introduced.
Material Components Alternative
If your app already uses Material Components, you can apply corner style through theme overlays instead of a custom window drawable for every dialog. This reduces duplicated XML and keeps branding consistent.
Using theme overlays is especially useful when multiple dialogs share the same corner radius and elevation policy.
Keep Dialog Logic Decoupled
Custom dialogs often accumulate business logic quickly. Keep them maintainable by passing data and callbacks through clear interfaces, then handling decisions in view models or presenter layers. This keeps dialog classes focused on rendering and interaction. It also makes UI tests simpler because behavior can be mocked without recreating full business dependencies.
Common Pitfalls
- Styling only layout background and forgetting window background.
- Applying window size before
show, which can fail silently. - Hardcoding pixel values that break on different densities.
- Ignoring dark theme variants and creating poor contrast.
- Putting business logic in dialog construction instead of callbacks or view models.
Summary
- Define rounded appearance in a reusable drawable resource.
- Keep content layout and window styling responsibilities separate.
- Apply custom window background and insets after dialog creation.
- Prefer
DialogFragmentfor lifecycle resilient implementations. - Validate design on multiple devices, themes, and accessibility settings.

