• Stars
    star
    890
  • Rank 49,406 (Top 1.0 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.

Maven Central API Android Weekly

Github Followers GitHub stars GitHub forks GitHub watchers Twitter Follow

Material Dialogs for Android 📱

📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.

1. Material Dialog 2. Animated Material Dialog 3. Bottom Sheet Material Dialog 4. Animated Bottom Sheet Material Dialog

Table of Contents:

Introduction

MaterialDialog library is built upon Google's Material Design library. This API will be useful to create rich, animated, beautiful dialogs in Android app easily. This library implements Airbnb's Lottie library to render After Effects animation in app. Refer this for Lottie documentation.

Types of Dialog

MaterialDialog library provides two types of dialog i.e.

1. Material Dialog 2. Bottom Sheet Material Dialog
This is basic material dialog which has two material buttons (Same as Android's AlertDialog) as you can see below. This is Bottom Sheet material dialog which has two material buttons which is showed from bottom of device as you can see below.

Implementation

Implementation of Material Dialog library is so easy. You can check /app directory for demo. Let's have look on basic steps of implementation.

Prerequisite

i. Gradle

In Build.gradle of app module, include these dependencies. If you want to show animations, include Lottie animation library.

This library is available on MavenCentreal

repositories {
    mavenCentral()
}

dependencies {

    // Material Dialog Library
    implementation 'dev.shreyaspatil.MaterialDialog:MaterialDialog:2.2.3'

    // Material Design Library
    implementation 'com.google.android.material:material:1.0.0'

    // Lottie Animation Library
    implementation 'com.airbnb.android:lottie:3.3.6'
}

ii. Set up Material Theme

Setting Material Theme to app is necessary before implementing Material Dialog library. To set it up, update styles.xml of values directory in app.

<resources>
    <style name="AppTheme" parent="Theme.MaterialComponents.Light">
        <!-- Customize your theme here. -->
        ...
    </style>
</resources>

These are required prerequisites to implement Material Dialog library.

iii. Customize Dialog Theme (Optional)

If you want to customize dialog view, you can override style in styles.xml as below.

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:fontFamily">@font/montserrat</item>

        <!-- Customize your theme here. -->
        <item name="material_dialog_background">#FFFFFF</item>
        <item name="material_dialog_title_text_color">#000000</item>
        <item name="material_dialog_message_text_color">#5F5F5F</item>
        <item name="material_dialog_positive_button_color">@color/colorAccent</item>
        <item name="material_dialog_positive_button_text_color">#FFFFFF</item>
        <item name="material_dialog_negative_button_text_color">@color/colorAccent</item>
    </style>

Create Dialog Instance

As there are two types of dialogs in library. Material Dialogs are instantiated as follows.

i. Material Dialog

MaterialDialog class is used to create Material Dialog. Its static Builder class is used to instantiate it. After building, to show the dialog, show() method of MaterialDialog is used.

        MaterialDialog mDialog = new MaterialDialog.Builder(this)
                .setTitle("Delete?")
                .setMessage("Are you sure want to delete this file?")
                .setCancelable(false)
                .setPositiveButton("Delete", R.drawable.ic_delete, new MaterialDialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        // Delete Operation
                    }
                })
                .setNegativeButton("Cancel", R.drawable.ic_close, new MaterialDialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        dialogInterface.dismiss();
                    }
                })
                .build();

        // Show Dialog
        mDialog.show();

ii. Bottom Sheet Material Dialog

BottomSheetMaterialDialog class is used to create Bottom Sheet Material Dialog. Its static Builder class is used to instantiate it. After building, to show the dialog, show() method of BottomSheetMaterialDialog is used.

        BottomSheetMaterialDialog mBottomSheetDialog = new BottomSheetMaterialDialog.Builder(this)
                .setTitle("Delete?")
                .setMessage("Are you sure want to delete this file?")
                .setCancelable(false)
                .setPositiveButton("Delete", R.drawable.ic_delete, new BottomSheetMaterialDialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show();
                        dialogInterface.dismiss();
                    }
                })
                .setNegativeButton("Cancel", R.drawable.ic_close, new BottomSheetMaterialDialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        Toast.makeText(getApplicationContext(), "Cancelled!", Toast.LENGTH_SHORT).show();
                        dialogInterface.dismiss();
                    }
                })
                .build();

        // Show Dialog
        mBottomSheetDialog.show();

Text Alignment

Text alignment is supported for title and message of a dialog. It's configurable while building a dialog. If it's not provided in builder, TextAlignment.CENTER is considered by default i.e. it'll be always aligned in a center.

Following Alignment Enum Values are allowed to be used for Dialog text alignment:

  • TextAlignment.START: Aligns text at start / left.
  • TextAlignment.CENTER: Aligns text at center.
  • TextAlignment.END: Aligns text at end / right.

Example usage:

        MaterialDialog mDialog = new MaterialDialog.Builder(this)
                .setTitle("Lorem Ipsum Title", TextAlignment.START)
                .setMessage("Lorem Ipsum Message", TextAlignment.START)

HTML formatting for Message

HTML spanned text is supported only for dialog's message. While setting a message, you can directly provide Spanned instance as shown in following example.

        MaterialDialog mDialog = new MaterialDialog.Builder(this)
                .setMessage(Html.fromText("<b>Lorem <i>Ipsum</i></b>. <br> Click <a href=\"https://example.com\">here</a> for more information"))

Show Animations

Material Dialog Bottom Sheet Material Dialog

Animations in this library are implemented using Lottie animation library. You can get free animations files here. You can find varieties of animation files on https://lottiefiles.com. *.json file downloaded from LottieFiles should be placed in android project. There are two ways to place animation file (*.json).

For example, here delete_anim.json animation file is used to show file delete animation.

i. Using Resource File

Downloaded json file should placed in raw directory of res.

In code, setAnimation() method of Builder is used to set Animation to the dialog.

Prototype :

setAnimation(int resourceId)

Resource file should be passed to method. e.g. R.raw.delete_anim.

        MaterialButton mDialog = new MaterialDialog.Builder(this)
                .setAnimation(R.raw.delete_anim)

ii. Using Asset File

Downloaded json file should placed in asset directory.

In code, setAnimation() method of Builder is used to set Animation to the dialog.

Prototype:

setAnimation(String fileName)

Only file name with extensions should passed to method.

        MaterialButton mDialog = new MaterialDialog.Builder(this)
                // Other Methods to create Dialog........               
                .setAnimation("delete_anim.json")               
                //...

iii. Getting LottieAnimationView

To get View of Animation for any operations, there is a method in Material Dialogs which returns LottieAnimationView of dialog.

        // Get Animation View
        LottieAnimationView animationView = mDialog.getAnimationView();
        // Do operations on animationView

Dialog State Listeners

There are three callback events and listeners for Dialog.

Following are interfaces for implementations:

  • OnShowListener() - Listens for dialog Show event. Its onShow() is invoked when dialog is displayed.
  • OnCancelListener() - Listens for dialog Cancel event. Its onCancel() is invoked when dialog is cancelled.
  • OnDismissListener() - Listens for dialog Dismiss event. Its onDismiss() is dismiss when dialog is dismissed.
       ... 
       mDialog.setOnShowListener(this);
       mDialog.setOnCancelListener(this);
       mDialog.setOnDismissListener(this);
    }
    
    @Override
    public void onShow(DialogInterface dialogInterface) {
        // Dialog is Displayed
    }

    @Override
    public void onCancel(DialogInterface dialogInterface) {
        // Dialog is Cancelled
    }

    @Override
    public void onDismiss(DialogInterface dialogInterface) {
        // Dialog is Dismissed
    }
}

Contribute

Let's develop with collaborations. We would love to have contributions by raising issues and opening PRs. Filing an issue before PR is must. See Contributing Guidelines.

Credits

This library is built using following open-source libraries.

License

Project is published under the Apache 2.0 license. Feel free to clone and modify repo as you want, but don't forget to add reference to authors :)

More Repositories

1

Foodium

🍲Foodium is a sample food blog Android application 📱 built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, Flow, Dagger 2/Hilt, Architecture Components, MVVM, Room, Retrofit, Moshi, Material Components).
Kotlin
2,192
star
2

NotyKT

📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.
Kotlin
1,488
star
3

Capturable

🚀Jetpack Compose utility library for capturing Composable content and transforming it into Bitmap Image🖼️
Kotlin
596
star
4

permission-flow-android

Know about real-time state of a Android app Permissions with Kotlin Flow APIs.
Kotlin
406
star
5

EasyUpiPayment-Android

📱Android Library to implement UPI Payment integration easily in Android App 💳💸
Kotlin
318
star
6

Flutter2GoogleSheets-Demo

A Demo application📱 which stores User feedback from 💙Flutter application into Google Sheets🗎 using Google AppScript.
Dart
293
star
7

mutekt

Simplify mutating "immutable" state models (a Kotlin multiplatform library)
Kotlin
236
star
8

compose-report-to-html

A utility (Gradle Plugin + CLI) to convert Jetpack Compose compiler metrics and reports to beautified HTML page.
Kotlin
213
star
9

MaterialNavigationView-Android

📱 Android Library to implement Rich, Beautiful, Stylish 😍 Material Navigation View for your project with Material Design Guidelines. Easy to use.
Kotlin
199
star
10

Foodium-KMM

📱Sample application built to demonstrate the use of Kotlin Multiplatform Mobile for developing Android and iOS applications using Jetpack Compose 🚀.
Kotlin
184
star
11

Covid19-Notifier-IN

A sample Android App which notifies about COVID19 cases in 🇮🇳India after every 1 hour.
Kotlin
146
star
12

FCM-OnDeviceNotificationScheduler

Demo implementation to Schedule FCM Notifications on Android Device using AlarmManager + WorkManager.
Kotlin
112
star
13

AndroidFastlaneCICD

📱A sample repository to demonstrate the Automate publishing🚀 app to the Google Play Store with GitHub Actions⚡+ Fastlane🏃.
Kotlin
99
star
14

LiveStream-kt

LiveStream is a simple class which makes communication easy among different modules of your application.
Kotlin
96
star
15

LiveStream-Flutter

Dart package to which makes data communication easy among different modules of your application.
Dart
74
star
16

CellLocationFind-Android

A sample android app which extracts the location of a device using the SIM card details by extracting network details.
Kotlin
65
star
17

GitKtDroid

A sample Android application📱 built with Kotlin for #30DaysOfKotlin
Kotlin
56
star
18

DataStoreExample

Jetpack DataStore is a data storage solution. It allows us to store key-value pairs (like SharedPreferences) or typed objects with protocol buffers. DataStore uses Kotlin and Coroutines + Flow to store data synchronously with consistency and transaction support 😍
Kotlin
56
star
19

FirebaseFlowExample

A sample android application which demonstrates use of Kotlin Coroutines Flow with Firebase Cloud Firestore.
Kotlin
51
star
20

PatilShreyas.github.io

My Portfolio hosted on GitHub pages.
HTML
43
star
21

FirebaseRecyclerPagination

[DEPRECATED] Android Library to implement Paging support for Realtime Database in RecyclerView.
Java
35
star
22

TikKT

⌛ A simple timer app built with super powerful Jetpack Compose for #AndroidDevChallenge
Kotlin
33
star
23

ViewModelGoodPractice

This is an example repository to demonstrate the good practices of using ViewModel and how usage of AndroidViewModel can make things worst in a codebase
Kotlin
31
star
24

AndroidGPR

Demonstration of deploying Android library to the GitHub Package Registry using GitHub Actions CI/CD
Kotlin
25
star
25

PetyKT

A pet adoption app UI built with super powerful Jetpack Compose for #AndroidDevChallenge
Kotlin
22
star
26

FirestorePagingDemo-Android

Demo app for implementation of Firestore Paging library in Android app.
Java
20
star
27

library-ci

Sample repository to demonstrate usage of GitHub Actions CI's workflow dispatch to automate publishing of a library to Maven Central
Kotlin
17
star
28

PassengerSecurity-SIH2018

This is our SIH2018 and Third Year Mini Project - Android app for Passenger to file FIR Online.
Java
14
star
29

FirebaseRecyclerUpdateQuery-Demo

🔥Example app 📱 to demonstrate change query of Firebase/Firestore in RecyclerView without changing whole adapter.
Kotlin
9
star
30

material_dialog

[IN DEVELOPMENT - NOT AVAILABLE YET] 📱Flutter package to implement animated, 😍beautiful, 🎨stylish Material Dialog in apps easily.
Dart
9
star
31

CollegePracticals

My College Practicals
C
8
star
32

EasyDatabase

Java API to easily implement JDBC-ODBC Database connection and operations.
Java
8
star
33

play-with-perfetto

Python
7
star
34

GDGPune-DevFest19-Android

Kotlin
6
star
35

ProfileWeb-Flutter

Playing with Flutter Web to create profile.
Dart
5
star
36

MyCart-CLI

A sample E-Commerce Command Line Interface app built using Kotlin!
Kotlin
5
star
37

BasicsOfDagger-Java

A simple example to explain the Dependency Injection💉 framework - Dagger🔪
Java
5
star
38

PatilShreyas

My profile README
5
star
39

my-blog

4
star
40

Template-NodeJS-MySQL

Sample NodeJS Web app to Test MySQL Operations.
HTML
4
star
41

Blog

My blog hosted on Netlify
JavaScript
3
star
42

MyBlog

Sample blog web application using Python Django + Postgres.
CSS
3
star
43

AndroidWorkshop

Resource of Android Workshop being conducted at IT Department, DYPCOE, Pune
Java
3
star
44

AndroidLibDemo

Publish Android Library to Bintray JCenter using GitHub Actions CI
Kotlin
2
star
45

portfolio

A one-place to host your portfolio.
2
star
46

asj-android-example

This is example project for Android Study Jams workshop @ GDG Cloud Pune.
Kotlin
2
star
47

mytestsite

HTML
2
star
48

GatsbyBlog

CSS
1
star
49

netlify-functions-example

HTML
1
star
50

one-click-hugo-cms

CSS
1
star
51

ForestryBlogExample

1
star
52

empress-blog-netlify-casper-template

JavaScript
1
star
53

novela-hugo-starter

CSS
1
star
54

ScheduledActions-CITest

1
star
55

gatsby-starter-netlify-cms

JavaScript
1
star
56

novela-blog

1
star
57

gatsby-starter-minimal-blog

JavaScript
1
star
58

DummyFoodiumApi

Dummy Remote End Point API for Foodium app - https://github.com/PatilShreyas/Foodium
HTML
1
star