Material-style dialogs
Create beautiful success, error, warning, normal, progress, input, custom image, URL image, and custom view dialogs.
KAlertDialog is a modern, customizable, Material-style Android AlertDialog library for professional apps. Build success, error, warning, progress, input, custom view, URL image, and dark-mode dialogs with clean Java code.
dependencies {
implementation 'io.github.tutorialsandroid:kalertdialog:21.0.0'
implementation 'io.github.tutorialsandroid:progressx:7.0.5'
}
KAlertDialog includes modern presets, dark mode, custom views, input validation, image loading, progress helpers, button styling, font customization, and dynamic alert type changes.
Create beautiful success, error, warning, normal, progress, input, custom image, URL image, and custom view dialogs.
Use the autoNightMode constructor to automatically adapt dialogs when your Android app runs in night mode.
Control title, content, fonts, font weight, colors, alignment, buttons, icons, radius, elevation, and dim amount.
Build input dialogs with hint, default text, input type, max length, validation, and custom confirm callbacks.
Attach your own XML layout or custom View inside KAlertDialog using CUSTOM_VIEW_TYPE.
Switch from warning to success, error, or other dialog states after user actions.
Load remote images with circle crop, big image mode, placeholder, and error drawable support.
Use helper methods or direct shortcut APIs to customize progress color, radius, speed, and value.
Use onConfirm, onCancel, onDialogShow, and onDialogDismiss for cleaner callback-style code.
A major update focused on modern UI customization, better input handling, custom views, advanced button APIs, and improved documentation.
Examples of modern dialogs created with KAlertDialog. Keep these image files inside your repository under art/new/.
Add Maven Central and JitPack, then add KAlertDialog and ProgressX dependencies to your Android project.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'io.github.tutorialsandroid:kalertdialog:21.0.0'
implementation 'io.github.tutorialsandroid:progressx:7.0.5'
}
Latest KAlertDialog and ProgressX versions require your app to compile against Android API 37 or higher. Updating compileSdk is different from changing targetSdk or minSdk.
android {
compileSdk 37
defaultConfig {
minSdk 23
targetSdk 36
}
}
Copy-paste ready examples for common KAlertDialog use cases.
Create a simple dialog with only title text.
new KAlertDialog(this)
.setTitleText("Here's a message!")
.show();
KAlertDialog supports normal, success, error, warning, progress, input, image, URL image, and custom view dialogs.
KAlertDialog.NORMAL_TYPE
KAlertDialog.ERROR_TYPE
KAlertDialog.SUCCESS_TYPE
KAlertDialog.WARNING_TYPE
KAlertDialog.CUSTOM_IMAGE_TYPE
KAlertDialog.URL_IMAGE_TYPE
KAlertDialog.PROGRESS_TYPE
KAlertDialog.INPUT_TYPE
KAlertDialog.CUSTOM_VIEW_TYPE
Apply a modern style preset with professional radius, elevation, dim amount, and button styling.
new KAlertDialog(this, KAlertDialog.SUCCESS_TYPE, true)
.setTitleText("Success")
.setContentText("Your changes were saved successfully.")
.applyStyle(KAlertDialog.STYLE_MODERN)
.setConfirmClickListener("Done", dialog -> dialog.dismissWithAnimation())
.show();
Control dialog corner radius, elevation, dim amount, and background color.
new KAlertDialog(this, KAlertDialog.NORMAL_TYPE, true)
.setTitleText("Custom Appearance")
.setContentText("This dialog has custom radius, elevation and dim amount.")
.setDialogCornerRadius(30)
.setDialogElevation(14)
.setDimAmount(0.55f)
.setConfirmClickListener("Looks Good", null)
.show();
Show loading or processing states with progress helper APIs or direct shortcut methods.
new KAlertDialog(this, KAlertDialog.PROGRESS_TYPE, true)
.setTitleText("Processing")
.setContentText("Please wait while we prepare your request.")
.applyStyle(KAlertDialog.STYLE_MODERN)
.setProgressColor(Color.parseColor("#10B981"))
.setProgressSpinSpeed(1.1f)
.show();
Validate input before confirming and show an error message directly in the input field.
new KAlertDialog(this, KAlertDialog.INPUT_TYPE, true)
.setTitleText("Create Project")
.setContentText("Enter a project name with at least 3 characters.")
.applyStyle(KAlertDialog.STYLE_MODERN)
.setInputFieldHint("Project name")
.setInputFieldText("KAlertDialog")
.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS)
.setInputMaxLength(30)
.setInputError("Project name must be at least 3 characters")
.setInputValidator(input -> input != null && input.trim().length() >= 3)
.setOnInputConfirmListener((dialog, input) -> {
dialog.dismissWithAnimation();
Toast.makeText(this, "Created: " + input.trim(), Toast.LENGTH_SHORT).show();
})
.setConfirmClickListener("Create", null)
.show();
Attach your own XML layout inside KAlertDialog and access its views using getCustomView().
KAlertDialog dialog = new KAlertDialog(this, KAlertDialog.CUSTOM_VIEW_TYPE, true)
.setTitleText("Custom View")
.setContentText("This dialog uses your custom XML layout.")
.applyStyle(KAlertDialog.STYLE_MODERN)
.setCustomView(R.layout.customedittext)
.showCancelButton(true)
.setCancelClickListener("Cancel", kAlertDialog -> kAlertDialog.dismissWithAnimation());
dialog.setConfirmClickListener("Save", kAlertDialog -> {
View customView = kAlertDialog.getCustomView();
if (customView == null) {
return;
}
EditText editText = customView.findViewById(R.id.edit_query);
String value = editText.getText().toString().trim();
if (value.length() < 3) {
editText.setError("Please enter at least 3 characters");
return;
}
kAlertDialog.dismissWithAnimation();
});
dialog.show();
Load remote images as circle crop or big images with placeholder and error fallback.
new KAlertDialog(this, KAlertDialog.URL_IMAGE_TYPE, true)
.setTitleText("Big URL Image")
.setContentText("This image is loaded from a URL as a large image.")
.applyStyle(KAlertDialog.STYLE_ROUNDED)
.setURLImagePlaceholder(R.mipmap.ic_launcher)
.setURLImageError(R.mipmap.ic_launcher)
.setURLImage("https://example.com/image.png", KAlertDialog.IMAGE_BIG)
.setConfirmClickListener("Close", null)
.show();
Use fonts from assets or res/font and apply font weight to title, content, and buttons.
new KAlertDialog(this, KAlertDialog.NORMAL_TYPE, true)
.setTitleText("Font Weight")
.setContentText("Title is bold and content is italic.")
.setTitleFontAssets("fonts/os.ttf")
.setContentFontAssets("fonts/poppins_regular.ttf")
.setTitleFontWeight(Typeface.BOLD)
.setContentFontWeight(Typeface.ITALIC)
.setConfirmClickListener("OK", null)
.show();
Customize button text size, font weight, all-caps behavior, icons, colors, and drawable backgrounds.
new KAlertDialog(this, KAlertDialog.NORMAL_TYPE, true)
.setTitleText("Button Styling")
.setContentText("This example shows button text size, font weight, all caps control and button icons.")
.applyStyle(KAlertDialog.STYLE_MINIMAL)
.showCancelButton(true)
.setConfirmButtonTextSize(15)
.setCancelButtonTextSize(15)
.setConfirmButtonFontWeight(Typeface.BOLD)
.setCancelButtonFontWeight(Typeface.BOLD)
.setConfirmButtonAllCaps(false)
.setCancelButtonAllCaps(false)
.setConfirmButtonIcon(android.R.drawable.checkbox_on_background)
.setCancelButtonIcon(android.R.drawable.ic_menu_close_clear_cancel)
.setConfirmClickListener("Accept", dialog -> dialog.dismissWithAnimation())
.setCancelClickListener("Decline", dialog -> dialog.dismissWithAnimation())
.show();
Use callback-style APIs for confirm, cancel, show, and dismiss events.
new KAlertDialog(this, KAlertDialog.NORMAL_TYPE, true)
.setTitleText("Callbacks")
.setContentText("This dialog shows modern listener APIs.")
.applyStyle(KAlertDialog.STYLE_MODERN)
.showCancelButton(true)
.onDialogShow(dialog -> {
Toast.makeText(this, "Dialog shown", Toast.LENGTH_SHORT).show();
})
.onDialogDismiss(dialog -> {
Toast.makeText(this, "Dialog dismissed", Toast.LENGTH_SHORT).show();
})
.onConfirm(dialog -> {
Toast.makeText(this, "Confirmed", Toast.LENGTH_SHORT).show();
dialog.dismissWithAnimation();
})
.onCancel(dialog -> {
Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
dialog.dismissWithAnimation();
})
.setConfirmClickListener("Confirm", null)
.setCancelClickListener("Cancel", null)
.show();
Change the alert type after user interaction, such as warning to success or error.
new KAlertDialog(this, KAlertDialog.WARNING_TYPE, true)
.setTitleText("Are you sure?")
.setContentText("You won't be able to recover this file!")
.showCancelButton(true)
.setCancelClickListener("Cancel", dialog -> {
dialog.setTitleText("Cancelled")
.setContentText("Your file is safe.")
.showCancelButton(false)
.setConfirmClickListener("OK", null)
.changeAlertType(KAlertDialog.ERROR_TYPE);
})
.setConfirmClickListener("Delete", dialog -> {
dialog.setTitleText("Deleted")
.setContentText("Your file has been deleted.")
.showCancelButton(false)
.setConfirmClickListener("OK", null)
.changeAlertType(KAlertDialog.SUCCESS_TYPE);
})
.show();
The most-used constants and methods in one place.
new KAlertDialog(context)
new KAlertDialog(context, autoNightMode)
new KAlertDialog(context, alertType, autoNightMode)
KAlertDialog.NORMAL_TYPE
KAlertDialog.ERROR_TYPE
KAlertDialog.SUCCESS_TYPE
KAlertDialog.WARNING_TYPE
KAlertDialog.CUSTOM_IMAGE_TYPE
KAlertDialog.URL_IMAGE_TYPE
KAlertDialog.PROGRESS_TYPE
KAlertDialog.INPUT_TYPE
KAlertDialog.CUSTOM_VIEW_TYPE
KAlertDialog.STYLE_CLASSIC
KAlertDialog.STYLE_MODERN
KAlertDialog.STYLE_MINIMAL
KAlertDialog.STYLE_ROUNDED
.setTitleText("Title")
.setContentText("Content")
.setTitleTextSize(20)
.setContentTextSize(16)
.setTitleColor(R.color.color)
.setContentColor(R.color.color)
.setTitleFontWeight(Typeface.BOLD)
.setContentFontWeight(Typeface.NORMAL)
.setConfirmClickListener("OK", listener)
.setCancelClickListener("Cancel", listener)
.showConfirmButton(true)
.showCancelButton(true)
.setConfirmButtonTextSize(15)
.setConfirmButtonFontWeight(Typeface.BOLD)
.setConfirmButtonAllCaps(false)
.setConfirmButtonIcon(R.drawable.icon)
.setInputFieldHint("Hint")
.setInputFieldText("Default text")
.setInputType(InputType.TYPE_CLASS_TEXT)
.setInputMaxLength(30)
.setInputError("Error message")
.setInputValidator(input -> input.trim().length() >= 3)
.setOnInputConfirmListener((dialog, input) -> { })
.getInputText()
.setCustomView(R.layout.custom_layout)
.setCustomView(view)
.getCustomView()
.setURLImage("https://example.com/image.png", KAlertDialog.IMAGE_CIRCLE)
.setURLImage("https://example.com/image.png", KAlertDialog.IMAGE_BIG)
.setURLImagePlaceholder(R.drawable.placeholder)
.setURLImageError(R.drawable.error_image)
.getProgressHelper()
.setProgressColor(Color.GREEN)
.setProgressColorResource(R.color.color)
.setProgressWidth(6)
.setProgressValue(0.5f)
.setProgressInstantValue(0.5f)
.setProgressSpinSpeed(1.1f)
.setProgressCircleRadius(80)
.onConfirm(dialog -> { })
.onCancel(dialog -> { })
.onDialogShow(dialog -> { })
.onDialogDismiss(dialog -> { })
Quick answers for setup and common issues.
KAlertDialog is a modern Material-style Android AlertDialog library for Java Android apps. It supports success, error, warning, progress, input, custom image, URL image, and custom view dialogs.
KAlertDialog 21.0.0 requires compileSdk 37 or higher because the latest KAlertDialog and ProgressX libraries are compiled with Android API 37.
No. compileSdk controls which APIs your app can compile against. targetSdk controls Android runtime behavior changes, and minSdk controls the minimum installable Android version.
Yes. Pass true in the constructor to enable auto dark mode behavior.
Yes. Use CUSTOM_VIEW_TYPE with setCustomView(R.layout.your_layout) or setCustomView(view), then access it using getCustomView().
Make sure custom_big_image has a fixed height such as 170dp, the parent image frame has match_parent width, and IMAGE_BIG uses centerCrop in Glide.
Install the latest version, explore the sample app, and star the GitHub repository if this library helps your Android projects.