Skip to content

Netsnake-TN/material-flashbar

Repository files navigation

Material Flashbar

License: MIT API Material Design

Flashbar is a Material Design 3 compliant notification library for Android that provides beautiful, customizable, and accessible notification bars with support for animations, swipe-to-dismiss, multiple action buttons, and more.

Features

Material Design 3 Compliance - Follows Google's latest Material Design 3 guidelines with expressive design elements
WCAG 2.1 AA Accessibility - Fully accessible with proper contrast ratios, screen reader support, and keyboard navigation
🎨 Expressive Design - Vibrant color palettes, smooth animations, and delightful interactions
👆 Swipe-to-Dismiss - Intuitive gesture support for dismissing notifications
🎯 Multiple Action Buttons - Support for primary, positive, and negative action buttons
📊 Progress Indicators - Left and right positioned progress bars with customizable styles
🌓 Dark Theme Support - Automatic dark theme adaptation with semantic colors
🎭 Custom Animations - Flexible enter/exit animations with icon animation support
🔔 Vibration Feedback - Haptic feedback on show and dismiss events
⌨️ Keyboard Navigation - Full keyboard support for accessibility
📱 Flexible Positioning - Top or bottom positioning with edge-to-edge support

Installation

Add the JitPack repository to your project-level build.gradle or settings.gradle:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

Then add the dependency to your module-level build.gradle:

dependencies {
    implementation 'com.github.Netsnake-TN:material-flashbar:1.0.0'
}

Or add to your build.gradle.kts:

dependencies {
    implementation("com.github.Netsnake-TN:material-flashbar:1.0.0")
}

Requirements:

  • Min SDK: 26 (Android 8.0)
  • Target SDK: 35 (Android 15)
  • Compile SDK: 35
  • Material Components: 1.14.0-alpha08 or higher

Note: Replace 1.0.0 with the latest version from JitPack.

Quick Start

Basic Usage

new Flashbar.Builder(activity)
    .gravity(Flashbar.Gravity.BOTTOM)
    .title("Download Complete")
    .message("File has been downloaded successfully")
    .primaryActionText("Open")
    .primaryActionTapListener(bar -> {
        // Handle action
        bar.dismiss();
    })
    .build()
    .show();

Using Presets

// Success notification
FlashbarPresets.success(this, "Success!", "Your changes have been saved")
    .show();

// Error notification with action
FlashbarPresets.error(this, "Error", "Failed to save file")
    .primaryActionText("Retry", bar -> retryOperation())
    .show();

// Loading indicator
FlashbarPresets.loading(this, "Processing your request...")
    .show();

Documentation

API Overview

The Flashbar library uses the Builder Pattern for fluent API design. All configuration is done through the Flashbar.Builder class, which provides comprehensive customization options.

Complete API Reference

Flashbar Class

The main entry point for creating and displaying flashbars.

Constants

Constant Value Description
DURATION_SHORT 1000L Short duration (1 second)
DURATION_LONG 2500L Long duration (2.5 seconds)
DURATION_INDEFINITE -1L Indefinite duration (no auto-dismiss)

Public Methods

show()

Displays the flashbar on the screen with configured animations and settings.

flashbar.show();

Note: If the flashbar is already showing, this method does nothing.

dismiss()

Dismisses the flashbar with the configured exit animation.

flashbar.dismiss();

Note: If the flashbar is not showing, this method does nothing.

setCloseButtonPosition(CloseButtonPosition position)

Changes the position of the close button after the flashbar has been created.

flashbar.setCloseButtonPosition(Flashbar.CloseButtonPosition.BOTTOM_CENTER);

Parameters:

  • position - The desired close button position (CENTER_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT)
setCloseButtonIconTint(int color)

Sets the tint color for the close button icon.

flashbar.setCloseButtonIconTint(Color.WHITE);

Parameters:

  • color - The tint color to apply
isShowing()

Checks if the flashbar is currently showing (including during show animation).

boolean showing = flashbar.isShowing();

Returns: true if showing, false otherwise

isShown()

Checks if the flashbar has completed showing (animation finished).

boolean shown = flashbar.isShown();

Returns: true if shown, false otherwise

Flashbar.Builder Class

Provides fluent API for configuring flashbars.

Constructor

Builder(Activity activity)

Creates a new Flashbar Builder.

Flashbar.Builder builder = new Flashbar.Builder(activity);

Parameters:

  • activity - The activity to display the flashbar in

Positioning Methods

gravity(Gravity gravity)

Sets the vertical position of the flashbar.

.gravity(Flashbar.Gravity.BOTTOM)

Options:

  • Gravity.TOP - Position at the top of the screen
  • Gravity.BOTTOM - Position at the bottom of the screen (default)

Appearance Methods

backgroundColor(@ColorInt int color)

Sets the background color.

.backgroundColor(Color.parseColor("#6750A4"))
backgroundColorRes(@ColorRes int colorId)

Sets the background color from a color resource.

.backgroundColorRes(R.color.primaryContainer)
backgroundDrawable(Drawable drawable)

Sets a custom background drawable.

.backgroundDrawable(ContextCompat.getDrawable(this, R.drawable.custom_bg))
backgroundDrawable(@DrawableRes int drawableId)

Sets a custom background drawable from a resource.

.backgroundDrawable(R.drawable.custom_bg)
shapeAppearanceOverlay(@StyleRes int styleResId)

Applies a shape appearance overlay style.

.shapeAppearanceOverlay(R.style.ShapeAppearanceOverlay_Expressive)
shapeAppearanceModel(ShapeAppearanceModel model)

Applies a custom shape appearance model.

ShapeAppearanceModel model = new ShapeAppearanceModel.Builder()
    .setAllCorners(CornerFamily.ROUNDED, 24f)
    .build();
.shapeAppearanceModel(model)
cornerRadius(float radius)

Sets a uniform corner radius for all corners.

.cornerRadius(24f)
cornerRadii(float topLeft, float topRight, float bottomRight, float bottomLeft)

Sets individual corner radii for each corner.

.cornerRadii(8f, 32f, 16f, 24f)
material3ShapeStyle(Material3ShapeStyle style)

Applies a Material 3 shape style.

.material3ShapeStyle(Flashbar.Material3ShapeStyle.LARGE)

Options:

  • NONE - No corners (sharp edges)
  • EXTRA_SMALL - Extra small corner size
  • SMALL - Small corner size
  • MEDIUM - Medium corner size (default)
  • LARGE - Large corner size
  • EXTRA_LARGE - Extra large corner size
  • FULL - Fully rounded corners (pill shape)

Content Methods

title(String title)

Sets the title text.

.title("Notification Title")
title(@StringRes int titleId)

Sets the title text from a string resource.

.title(R.string.notification_title)
title(Spanned title)

Sets a spanned title text (for rich text formatting).

.title(Html.fromHtml("<b>Bold</b> Title"))
titleColor(@ColorInt int color)

Sets the title text color.

.titleColor(Color.WHITE)
titleColorRes(@ColorRes int colorId)

Sets the title text color from a color resource.

.titleColorRes(R.color.onPrimaryContainer)
titleSizeInPx(float size)

Sets the title text size in pixels.

.titleSizeInPx(24f)
titleSizeInSp(float size)

Sets the title text size in scaled pixels.

.titleSizeInSp(18f)
titleTypeface(Typeface typeface)

Sets the title text typeface.

.titleTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL))
titleAppearance(@StyleRes int appearance)

Applies a text appearance style to the title.

.titleAppearance(R.style.TextAppearance_Material3_TitleMedium)
titlePosition(TextPosition position)

Sets the title text position.

.titlePosition(Flashbar.TextPosition.CENTER)

Options:

  • DEFAULT - Left aligned (default)
  • CENTER - Center aligned
message(String message)

Sets the message text.

.message("This is the notification message")
message(@StringRes int messageId)

Sets the message text from a string resource.

.message(R.string.notification_message)
message(Spanned message)

Sets a spanned message text (for rich text formatting).

.message(Html.fromHtml("Message with <i>italic</i> text"))
messageColor(@ColorInt int color)

Sets the message text color.

.messageColor(Color.WHITE)
messageColorRes(@ColorRes int colorId)

Sets the message text color from a color resource.

.messageColorRes(R.color.onPrimaryContainer)
messageSizeInPx(float size)

Sets the message text size in pixels.

.messageSizeInPx(16f)
messageSizeInSp(float size)

Sets the message text size in scaled pixels.

.messageSizeInSp(14f)
messageTypeface(Typeface typeface)

Sets the message text typeface.

.messageTypeface(Typeface.create("sans-serif", Typeface.NORMAL))
messageAppearance(@StyleRes int appearance)

Applies a text appearance style to the message.

.messageAppearance(R.style.TextAppearance_Material3_BodyMedium)
messagePosition(TextPosition position)

Sets the message text position.

.messagePosition(Flashbar.TextPosition.CENTER)

Options:

  • DEFAULT - Left aligned (default)
  • CENTER - Center aligned

Icon Methods

showIcon()

Shows the icon with default scale (1.0f) and center crop scale type.

.showIcon()
showIcon(float scale)

Shows the icon with custom scale.

.showIcon(1.5f)
showIcon(float scale, ScaleType scaleType)

Shows the icon with custom scale and scale type.

.showIcon(1.5f, ImageView.ScaleType.CENTER_INSIDE)

Parameters:

  • scale - Icon scale multiplier (must be > 0)
  • scaleType - ImageView scale type (CENTER_CROP, CENTER_INSIDE, etc.)
icon(Drawable icon)

Sets the icon drawable.

.icon(ContextCompat.getDrawable(this, R.drawable.ic_notification))
icon(@DrawableRes int iconId)

Sets the icon from a drawable resource.

.icon(R.drawable.ic_notification)
icon(Bitmap bitmap)

Sets the icon from a bitmap.

.icon(bitmap)
iconColorFilter(@ColorInt int color)

Applies a color filter to the icon (default mode: SRC_IN).

.iconColorFilter(Color.WHITE)
iconColorFilter(@ColorInt int color, PorterDuff.Mode mode)

Applies a color filter to the icon with specified mode.

.iconColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN)
iconColorFilterRes(@ColorRes int colorId)

Applies a color filter from a color resource.

.iconColorFilterRes(R.color.icon_tint)
iconAnimation(FlashAnimIconBuilder builder)

Sets a custom icon animation.

.iconAnimation(FlashAnim.with(this).animateIcon().pulse().duration(1000))

Action Button Methods

primaryActionText(String text)

Sets the primary action button text.

.primaryActionText("OK")
primaryActionText(@StringRes int actionTextId)

Sets the primary action button text from a string resource.

.primaryActionText(R.string.action_ok)
primaryActionText(Spanned actionText)

Sets a spanned action button text.

.primaryActionText(Html.fromHtml("<b>OK</b>"))
primaryActionTextColor(@ColorInt int color)

Sets the primary action button text color.

.primaryActionTextColor(Color.WHITE)
primaryActionTextColorRes(@ColorRes int colorId)

Sets the primary action button text color from a color resource.

.primaryActionTextColorRes(R.color.onPrimary)
primaryActionBackgroundColor(@ColorInt int color)

Sets the primary action button background color.

.primaryActionBackgroundColor(Color.parseColor("#6750A4"))
primaryActionBackgroundColorRes(@ColorRes int colorId)

Sets the primary action button background color from a color resource.

.primaryActionBackgroundColorRes(R.color.primary)
primaryActionTextSizeInPx(float size)

Sets the primary action button text size in pixels.

.primaryActionTextSizeInPx(16f)
primaryActionTextSizeInSp(float size)

Sets the primary action button text size in scaled pixels.

.primaryActionTextSizeInSp(14f)
primaryActionTextTypeface(Typeface typeface)

Sets the primary action button text typeface.

.primaryActionTextTypeface(Typeface.DEFAULT_BOLD)
primaryActionTextAppearance(@StyleRes int appearance)

Applies a text appearance style to the primary action button.

.primaryActionTextAppearance(R.style.TextAppearance_Material3_LabelLarge)
primaryButtonPosition(PrimaryButtonPosition position)

Sets the primary action button position.

.primaryButtonPosition(Flashbar.PrimaryButtonPosition.BOTTOM_RIGHT)

Options:

  • CENTER_RIGHT - Center right (default)
  • BOTTOM_CENTER - Bottom center
  • BOTTOM_RIGHT - Bottom right
primaryButtonStyle(ButtonStyle style)

Sets the primary action button style.

.primaryButtonStyle(Flashbar.ButtonStyle.TEXT_ONLY)

Options:

  • DEFAULT - Default filled button
  • TEXT_ONLY - Text only button
  • ICON_ONLY - Icon only button
primaryActionIcon(@DrawableRes int iconRes)

Sets the primary action button icon.

.primaryActionIcon(R.drawable.ic_check)
primaryActionTapListener(OnActionTapListener listener)

Sets the primary action button tap listener.

.primaryActionTapListener(bar -> {
    // Handle action
    bar.dismiss();
})
primaryAction(String text, OnActionTapListener listener)

Convenience method to set both text and listener.

.primaryAction("OK", bar -> bar.dismiss())
primaryAction(@StringRes int textResId, OnActionTapListener listener)

Convenience method to set text from resource and listener.

.primaryAction(R.string.action_ok, bar -> bar.dismiss())

Positive Action Button Methods

Same methods as primary action button, but for the positive (accept) action:

  • positiveActionText(String text)
  • positiveActionText(@StringRes int actionTextId)
  • positiveActionText(Spanned actionText)
  • positiveActionTextColor(@ColorInt int color)
  • positiveActionTextColorRes(@ColorRes int colorId)
  • positiveActionBackgroundColor(@ColorInt int color)
  • positiveActionBackgroundColorRes(@ColorRes int colorId)
  • positiveActionTextSizeInPx(float size)
  • positiveActionTextSizeInSp(float size)
  • positiveActionTextTypeface(Typeface typeface)
  • positiveActionTextAppearance(@StyleRes int appearance)
  • positiveButtonStyle(ButtonStyle style)
  • positiveActionIcon(@DrawableRes int iconRes)
  • positiveActionTapListener(OnActionTapListener listener)
  • positiveAction(String text, OnActionTapListener listener)
  • positiveAction(@StringRes int textResId, OnActionTapListener listener)

Negative Action Button Methods

Same methods as primary action button, but for the negative (decline) action:

  • negativeActionText(String text)
  • negativeActionText(@StringRes int actionTextId)
  • negativeActionText(Spanned actionText)
  • negativeActionTextColor(@ColorInt int color)
  • negativeActionTextColorRes(@ColorRes int colorId)
  • negativeActionBackgroundColor(@ColorInt int color)
  • negativeActionBackgroundColorRes(@ColorRes int colorId)
  • negativeActionTextSizeInPx(float size)
  • negativeActionTextSizeInSp(float size)
  • negativeActionTextTypeface(Typeface typeface)
  • negativeActionTextAppearance(@StyleRes int appearance)
  • negativeButtonStyle(ButtonStyle style)
  • negativeActionIcon(@DrawableRes int iconRes)
  • negativeActionTapListener(OnActionTapListener listener)
  • negativeAction(String text, OnActionTapListener listener)
  • negativeAction(@StringRes int textResId, OnActionTapListener listener)

Close Button Methods

showCloseButton()

Shows the close button (default).

.showCloseButton()
showCloseButton(boolean show)

Shows or hides the close button.

.showCloseButton(true)
enableDismissButton()

Enables the dismiss button (auto-dismiss action button).

.enableDismissButton()
enableDismissButton(boolean enable)

Enables or disables the dismiss button.

.enableDismissButton(true)

Note: When dismiss button is enabled, close button is automatically disabled.

closeButtonPosition(CloseButtonPosition position)

Sets the close button position.

.closeButtonPosition(Flashbar.CloseButtonPosition.BOTTOM_LEFT)

Options:

  • CENTER_RIGHT - Center right (default)
  • BOTTOM_CENTER - Bottom center
  • BOTTOM_LEFT - Bottom left
setCloseButtonIconTint(int color)

Sets the close button icon tint color.

.setCloseButtonIconTint(Color.WHITE)
setCloseButtonIconSize(int sizeInDp)

Sets the close button icon size in density-independent pixels.

.setCloseButtonIconSize(32)
setCloseButtonIconPadding(int paddingInDp)

Sets the close button icon padding in density-independent pixels.

.setCloseButtonIconPadding(8)
setCloseButtonStyle(int styleResId)

Sets the close button style from a style resource.

.setCloseButtonStyle(R.style.Widget_Material3_Button_IconButton)

Progress Indicator Methods

showProgress(ProgressPosition position)

Shows a progress indicator at the specified position.

.showProgress(Flashbar.ProgressPosition.LEFT)

Options:

  • LEFT - Show progress on the left side
  • RIGHT - Show progress on the right side

Note: Cannot show progress at left if icon is set, or at right if action button is set.

progressTint(@ColorInt int color)

Sets the progress indicator color.

.progressTint(Color.parseColor("#6750A4"))
progressTintRes(@ColorRes int colorId)

Sets the progress indicator color from a color resource.

.progressTintRes(R.color.primary)
loadingStyle(LoadingStyle style)

Sets the loading indicator style.

.loadingStyle(Flashbar.LoadingStyle.CONTAINED)

Options:

  • NORMAL - Normal loading indicator (default)
  • CONTAINED - Contained loading indicator with background
loadingSize(LoadingSize size)

Sets the loading indicator size.

.loadingSize(Flashbar.LoadingSize.LARGE)

Options:

  • SMALL - Small (16dp)
  • MEDIUM - Medium (20dp, default)
  • LARGE - Large (24dp)

Duration Methods

duration(long milliseconds)

Sets the display duration.

.duration(Flashbar.DURATION_LONG)

Parameters:

  • milliseconds - Duration in milliseconds, or DURATION_INDEFINITE for no auto-dismiss

Throws: IllegalArgumentException if duration is not DURATION_INDEFINITE and not positive

Overlay Methods

showOverlay()

Shows a semi-transparent overlay behind the flashbar.

.showOverlay()
showOverlay(float alpha)

Shows an overlay with custom alpha (0.0 to 1.0).

.showOverlay(0.5f)

Parameters:

  • alpha - Overlay opacity (0.0 = transparent, 1.0 = opaque)

Throws: IllegalArgumentException if alpha is not between 0.0 and 1.0

overlayColor(@ColorInt int color)

Sets the overlay color.

.overlayColor(Color.parseColor("#80000000"))
overlayColorRes(@ColorRes int colorId)

Sets the overlay color from a color resource.

.overlayColorRes(R.color.scrim_50)
overlayBlockable()

Makes the overlay block clicks (default behavior when overlay is shown).

.overlayBlockable()

Interaction Methods

blockActivityInteraction(boolean block)

Blocks or allows interaction with the activity when flashbar is shown.

.blockActivityInteraction(true)

Parameters:

  • block - true to block activity interaction, false to allow passthrough (default)

Note: This is independent of overlay and dismiss-on-tap-outside functionality.

dismissOnTapOutside()

Enables dismiss on tap outside (default: disabled).

.dismissOnTapOutside()
dismissOnTapOutside(boolean enabled)

Enables or disables dismiss on tap outside.

.dismissOnTapOutside(true)
listenOutsideTaps(OnTapListener listener)

Sets a listener for taps outside the flashbar.

.listenOutsideTaps(flashbar -> {
    // Handle outside tap
})
listenBarTaps(OnTapListener listener)

Sets a listener for taps on the flashbar.

.listenBarTaps(flashbar -> {
    // Handle bar tap
})

Animation Methods

enterAnimation(FlashAnimBarBuilder builder)

Sets the enter animation.

.enterAnimation(FlashAnim.with(this).animateBar().enter().fromBottom().overshoot().duration(400))
exitAnimation(FlashAnimBarBuilder builder)

Sets the exit animation.

.exitAnimation(FlashAnim.with(this).animateBar().exit().fromBottom().accelerate().duration(300))

Gesture Methods

enableSwipeToDismiss()

Enables swipe-to-dismiss gesture.

.enableSwipeToDismiss()
enableSwipeToDismiss(boolean enable)

Enables or disables swipe-to-dismiss gesture.

.enableSwipeToDismiss(true)

Vibration Methods

vibrateOn(Vibration... vibrate)

Sets when to vibrate.

.vibrateOn(Flashbar.Vibration.SHOW, Flashbar.Vibration.DISMISS)

Options:

  • Vibration.SHOW - Vibrate when flashbar is shown
  • Vibration.DISMISS - Vibrate when flashbar is dismissed

Event Listener Methods

barShowListener(OnBarShowListener listener)

Sets a listener for show events.

.barShowListener(new Flashbar.OnBarShowListener() {
    @Override
    public void onShowing(Flashbar bar) {
        // Called when show animation starts
    }
    
    @Override
    public void onShowProgress(Flashbar bar, float progress) {
        // Called during show animation (progress: 0.0 to 1.0)
    }
    
    @Override
    public void onShown(Flashbar bar) {
        // Called when show animation completes
    }
})
barDismissListener(OnBarDismissListener listener)

Sets a listener for dismiss events.

.barDismissListener(new Flashbar.OnBarDismissListener() {
    @Override
    public void onDismissing(Flashbar bar, boolean isSwiped) {
        // Called when dismiss animation starts
    }
    
    @Override
    public void onDismissProgress(Flashbar bar, float progress) {
        // Called during dismiss animation (progress: 0.0 to 1.0)
    }
    
    @Override
    public void onDismissed(Flashbar bar, Flashbar.DismissEvent event) {
        // Called when dismiss animation completes
        // event can be TIMEOUT, MANUAL, TAP_OUTSIDE, or SWIPE
    }
})

Build Methods

build()

Builds the Flashbar instance.

Flashbar flashbar = new Flashbar.Builder(activity)
    .title("Title")
    .message("Message")
    .build();

Returns: A configured Flashbar instance

show()

Builds and immediately shows the flashbar.

new Flashbar.Builder(activity)
    .title("Title")
    .message("Message")
    .show();

Enums

Gravity

Vertical positioning options.

Flashbar.Gravity.TOP    // Position at top
Flashbar.Gravity.BOTTOM // Position at bottom (default)

DismissEvent

Dismiss event types.

Flashbar.DismissEvent.TIMEOUT     // Dismissed due to timeout
Flashbar.DismissEvent.MANUAL      // Dismissed manually via dismiss()
Flashbar.DismissEvent.TAP_OUTSIDE // Dismissed by tapping outside
Flashbar.DismissEvent.SWIPE       // Dismissed by swiping

Vibration

Haptic feedback targets.

Flashbar.Vibration.SHOW    // Vibrate when shown
Flashbar.Vibration.DISMISS // Vibrate when dismissed

ProgressPosition

Progress indicator position options.

Flashbar.ProgressPosition.LEFT  // Show progress on left
Flashbar.ProgressPosition.RIGHT // Show progress on right

CloseButtonPosition

Close button position options.

Flashbar.CloseButtonPosition.CENTER_RIGHT  // Center right (default)
Flashbar.CloseButtonPosition.BOTTOM_CENTER // Bottom center
Flashbar.CloseButtonPosition.BOTTOM_LEFT   // Bottom left

TextPosition

Text position options for title and message.

Flashbar.TextPosition.DEFAULT // Left aligned (default)
Flashbar.TextPosition.CENTER  // Center aligned

PrimaryButtonPosition

Primary button position options.

Flashbar.PrimaryButtonPosition.CENTER_RIGHT  // Center right (default)
Flashbar.PrimaryButtonPosition.BOTTOM_CENTER // Bottom center
Flashbar.PrimaryButtonPosition.BOTTOM_RIGHT  // Bottom right

ButtonStyle

Action button style options.

Flashbar.ButtonStyle.DEFAULT    // Default filled button
Flashbar.ButtonStyle.TEXT_ONLY  // Text only button
Flashbar.ButtonStyle.ICON_ONLY  // Icon only button

LoadingStyle

Loading indicator style options.

Flashbar.LoadingStyle.NORMAL    // Normal loading indicator (default)
Flashbar.LoadingStyle.CONTAINED // Contained loading indicator with background

LoadingSize

Loading indicator size options.

Flashbar.LoadingSize.SMALL  // Small (16dp)
Flashbar.LoadingSize.MEDIUM // Medium (20dp, default)
Flashbar.LoadingSize.LARGE  // Large (24dp)

Material3ShapeStyle

Material 3 shape style constants.

Flashbar.Material3ShapeStyle.NONE         // No corners (sharp edges)
Flashbar.Material3ShapeStyle.EXTRA_SMALL  // Extra small corner size
Flashbar.Material3ShapeStyle.SMALL        // Small corner size
Flashbar.Material3ShapeStyle.MEDIUM       // Medium corner size (default)
Flashbar.Material3ShapeStyle.LARGE        // Large corner size
Flashbar.Material3ShapeStyle.EXTRA_LARGE  // Extra large corner size
Flashbar.Material3ShapeStyle.FULL         // Fully rounded corners (pill shape)

Interfaces

OnActionTapListener

Listener for action button taps.

public interface OnActionTapListener {
    void onActionTapped(Flashbar bar);
}

Usage:

.primaryActionTapListener(bar -> {
    // Handle action
    bar.dismiss();
})

OnBarDismissListener

Listener for dismiss events.

public interface OnBarDismissListener {
    void onDismissing(Flashbar bar, boolean isSwiped);
    void onDismissProgress(Flashbar bar, float progress);
    void onDismissed(Flashbar bar, DismissEvent event);
}

Usage:

.barDismissListener(new Flashbar.OnBarDismissListener() {
    @Override
    public void onDismissing(Flashbar bar, boolean isSwiped) {
        // Called when dismiss starts
    }
    
    @Override
    public void onDismissProgress(Flashbar bar, float progress) {
        // Called during dismiss (0.0 to 1.0)
    }
    
    @Override
    public void onDismissed(Flashbar bar, Flashbar.DismissEvent event) {
        // Called when dismiss completes
    }
})

OnTapListener

Listener for tap events.

public interface OnTapListener {
    void onTap(Flashbar flashbar);
}

Usage:

.listenBarTaps(bar -> {
    // Handle bar tap
})

OnBarShowListener

Listener for show events.

public interface OnBarShowListener {
    void onShowing(Flashbar bar);
    void onShowProgress(Flashbar bar, float progress);
    void onShown(Flashbar bar);
}

Usage:

.barShowListener(new Flashbar.OnBarShowListener() {
    @Override
    public void onShowing(Flashbar bar) {
        // Called when show starts
    }
    
    @Override
    public void onShowProgress(Flashbar bar, float progress) {
        // Called during show (0.0 to 1.0)
    }
    
    @Override
    public void onShown(Flashbar bar) {
        // Called when show completes
    }
})

FlashbarPresets

Preconfigured Flashbar presets for common use cases.

Success Preset

Creates a success notification with green accent.

// With string text
FlashbarPresets.success(activity, "Success!", "Your changes have been saved")
    .show();

// With string resources
FlashbarPresets.success(activity, R.string.success_title, R.string.success_message)
    .show();

// With action button
FlashbarPresets.success(activity, "Success!", "File uploaded successfully")
    .primaryActionText("View", bar -> openFile())
    .show();

Error Preset

Creates an error notification with red accent.

// With string text
FlashbarPresets.error(activity, "Error", "Failed to save file")
    .show();

// With string resources
FlashbarPresets.error(activity, R.string.error_title, R.string.error_message)
    .show();

// With action button
FlashbarPresets.error(activity, "Error", "Connection failed")
    .primaryActionText("Retry", bar -> retryConnection())
    .show();

Warning Preset

Creates a warning notification with amber accent.

// With string text
FlashbarPresets.warning(activity, "Warning", "Your session will expire soon")
    .show();

// With string resources
FlashbarPresets.warning(activity, R.string.warning_title, R.string.warning_message)
    .show();

// With action button
FlashbarPresets.warning(activity, "Warning", "Low battery")
    .primaryActionText("Save", bar -> saveWork())
    .show();

Info Preset

Creates an info notification with blue accent.

// With string text
FlashbarPresets.info(activity, "Information", "New features are available")
    .show();

// With string resources
FlashbarPresets.info(activity, R.string.info_title, R.string.info_message)
    .show();

// With action button
FlashbarPresets.info(activity, "Update Available", "Version 2.0 is ready")
    .primaryActionText("Update", bar -> startUpdate())
    .show();

Neutral Preset

Creates a neutral notification with gray accent for non-critical messages.

// With string text
FlashbarPresets.neutral(activity, "Notification", "This is a neutral message")
    .show();

// With string resources
FlashbarPresets.neutral(activity, R.string.neutral_title, R.string.neutral_message)
    .show();

Critical Preset

Creates a critical notification with strong red accent for destructive actions.

// With string text
FlashbarPresets.critical(activity, "Critical", "Data loss detected")
    .show();

// With string resources
FlashbarPresets.critical(activity, R.string.critical_title, R.string.critical_message)
    .show();

Toast Preset

Creates a toast-style minimal notification with auto-dismiss.

// With string text
FlashbarPresets.toast(activity, "Message saved")
    .show();

// With string resources
FlashbarPresets.toast(activity, R.string.toast_message)
    .show();

Minimal Preset

Creates a minimal notification with centered text and auto-dismiss.

// Short duration
FlashbarPresets.minimal(activity, "Title", "Message", Flashbar.DURATION_SHORT)
    .show();

// Long duration
FlashbarPresets.minimal(activity, "Title", "Message", Flashbar.DURATION_LONG)
    .show();

Custom Preset

Creates a generic notification with custom background color.

// With string text
FlashbarPresets.custom(activity, "Title", "Message", Color.parseColor("#6750A4"))
    .show();

// With string resources
FlashbarPresets.custom(activity, R.string.title, R.string.message, Color.parseColor("#6750A4"))
    .show();

Loading Preset

Creates a loading notification with progress indicator.

// With string text
FlashbarPresets.loading(activity, "Processing your request...")
    .show();

// With string resources
FlashbarPresets.loading(activity, R.string.loading_message)
    .show();

Primary Preset

Creates a notification with Material 3 primary color styling.

// With string text
FlashbarPresets.primary(activity, "Title", "Message")
    .show();

// With string resources
FlashbarPresets.primary(activity, R.string.title, R.string.message)
    .show();

Examples

Example 1: Basic Notification

new Flashbar.Builder(this)
    .title("Welcome!")
    .message("Thanks for using our app")
    .gravity(Flashbar.Gravity.BOTTOM)
    .show();

Example 2: Success with Action

new Flashbar.Builder(this)
    .title("Success!")
    .message("Your profile has been updated")
    .backgroundColorRes(R.color.successContainer)
    .titleColorRes(R.color.onSuccessContainer)
    .messageColorRes(R.color.onSuccessContainer)
    .icon(R.drawable.ic_check_circle)
    .primaryActionText("View Profile", bar -> {
        startActivity(new Intent(this, ProfileActivity.class));
        bar.dismiss();
    })
    .show();

Example 3: Error with Retry

new Flashbar.Builder(this)
    .title("Connection Error")
    .message("Failed to connect to server")
    .backgroundColorRes(R.color.errorContainer)
    .titleColorRes(R.color.onErrorContainer)
    .messageColorRes(R.color.onErrorContainer)
    .icon(R.drawable.ic_error)
    .positiveActionText("Retry", bar -> {
        retryConnection();
        bar.dismiss();
    })
    .negativeActionText("Cancel", bar -> bar.dismiss())
    .duration(Flashbar.DURATION_INDEFINITE)
    .show();

Example 4: Loading Indicator

Flashbar loadingBar = new Flashbar.Builder(this)
    .title("Loading")
    .message("Please wait...")
    .showProgress(Flashbar.ProgressPosition.LEFT)
    .progressTintRes(R.color.primary)
    .duration(Flashbar.DURATION_INDEFINITE)
    .showCloseButton(false)
    .build();

loadingBar.show();

// Later, dismiss when done
loadingBar.dismiss();

Example 5: Swipe to Dismiss

new Flashbar.Builder(this)
    .title("Swipe to Dismiss")
    .message("You can swipe this notification away")
    .enableSwipeToDismiss()
    .barDismissListener(new Flashbar.OnBarDismissListener() {
        @Override
        public void onDismissing(Flashbar bar, boolean isSwiped) {
            if (isSwiped) {
                Log.d("Flashbar", "Dismissed by swipe");
            }
        }
        
        @Override
        public void onDismissProgress(Flashbar bar, float progress) {
            Log.d("Flashbar", "Swipe progress: " + progress);
        }
        
        @Override
        public void onDismissed(Flashbar bar, Flashbar.DismissEvent event) {
            Log.d("Flashbar", "Dismissed: " + event);
        }
    })
    .show();

Example 6: Custom Animations

new Flashbar.Builder(this)
    .title("Custom Animations")
    .message("This notification has custom animations")
    .enterAnimation(FlashAnim.with(this)
        .animateBar()
        .enter()
        .fromBottom()
        .overshoot()
        .duration(500))
    .exitAnimation(FlashAnim.with(this)
        .animateBar()
        .exit()
        .fromBottom()
        .accelerate()
        .duration(300))
    .show();

Example 7: Overlay with Block

new Flashbar.Builder(this)
    .title("Modal Notification")
    .message("This blocks interaction with the activity")
    .showOverlay()
    .overlayColorRes(R.color.scrim_50)
    .blockActivityInteraction(true)
    .dismissOnTapOutside(true)
    .duration(Flashbar.DURATION_INDEFINITE)
    .show();

Example 8: Custom Shape

new Flashbar.Builder(this)
    .title("Custom Shape")
    .message("This has fully rounded corners")
    .material3ShapeStyle(Flashbar.Material3ShapeStyle.FULL)
    .show();

Example 9: Icon Animation

new Flashbar.Builder(this)
    .title("Animated Icon")
    .message("The icon is pulsing")
    .icon(R.drawable.ic_notification)
    .iconAnimation(FlashAnim.with(this)
        .animateIcon()
        .pulse()
        .duration(1000))
    .show();

Example 10: Multiple Actions

new Flashbar.Builder(this)
    .title("Confirm Action")
    .message("Are you sure you want to delete this item?")
    .positiveActionText("Delete", bar -> {
        deleteItem();
        bar.dismiss();
    })
    .negativeActionText("Cancel", bar -> bar.dismiss())
    .show();

Example 11: Centered Text

new Flashbar.Builder(this)
    .title("Centered Title")
    .message("Centered message text")
    .titlePosition(Flashbar.TextPosition.CENTER)
    .messagePosition(Flashbar.TextPosition.CENTER)
    .show();

Example 12: Vibration Feedback

new Flashbar.Builder(this)
    .title("With Haptics")
    .message("This vibrates on show and dismiss")
    .vibrateOn(Flashbar.Vibration.SHOW, Flashbar.Vibration.DISMISS)
    .show();

Example 13: Custom Close Button

new Flashbar.Builder(this)
    .title("Custom Close Button")
    .message("The close button is customized")
    .showCloseButton()
    .closeButtonPosition(Flashbar.CloseButtonPosition.BOTTOM_LEFT)
    .setCloseButtonIconTint(Color.WHITE)
    .setCloseButtonIconSize(32)
    .setCloseButtonIconPadding(8)
    .show();

Example 14: Progress with Percentage

FlashbarPresets.progressWithPercentage(this, "Downloading", "File download", 45)
    .show();

Example 15: Keyboard Navigation

new Flashbar.Builder(this)
    .title("Keyboard Accessible")
    .message("Press ESC or BACK to dismiss")
    .show();
// Users can press ESC or BACK key to dismiss

Theming

Flashbar supports Material 3 theming with semantic colors. Define these colors in your theme:

<style name="Theme.App" parent="Theme.Material3.DayNight">
    <!-- Flashbar Semantic Colors -->
    <item name="colorSuccessContainer">@color/successContainer</item>
    <item name="colorOnSuccessContainer">@color/onSuccessContainer</item>
    <item name="colorWarningContainer">@color/warningContainer</item>
    <item name="colorOnWarningContainer">@color/onWarningContainer</item>
    <item name="colorInfoContainer">@color/infoContainer</item>
    <item name="colorOnInfoContainer">@color/onInfoContainer</item>
</style>

Accessibility

Flashbar is WCAG 2.1 AA compliant and includes:

  • Proper color contrast ratios (4.5:1 for normal text, 3:1 for large text)
  • Screen reader announcements with descriptive content
  • Keyboard navigation support (ESC, BACK keys)
  • Touch target sizes meeting Material Design guidelines (minimum 48dp)
  • Focus management with visual feedback

ProGuard Rules

If using ProGuard, add these rules:

-keep class com.expressive.flashbar.** { *; }
-keep class com.google.android.material.** { *; }

License

MIT License

Copyright (c) 2026 Expressive Flashbar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the project
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

Support

For issues, questions, or suggestions, please open an issue on GitHub.


Made with ❤️ for the Android community

About

Material design 3 notification library for android

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages