Giter Club home page Giter Club logo

prettydialog's Introduction

PrettyDialog

Platform Api License JitpackBadge AndroidArsenalBadge

PrettyDialog is an Android Dialog library which is the customizable equivalent of SCLAlertView in iOS.

Example is available in app module.

Download

Gradle:

Add the following to your project level build.gradle:

allprojects {
   repositories {
      maven { url "https://jitpack.io" }
   }
}

Add this to your app build.gradle:

dependencies {
   compile 'com.github.mjn1369:prettydialog:1.0.0'
}

Usage

PrettyDialog extends Dialog class, so feel free to use its inherited functions.

Note: Default dialog has no title, message or any buttons. Just a close icon on top which you can dismiss the dialog by clicking on it.

Simple Dialog, No Customization:

new PrettyDialog(this)
	.setTitle("PrettyDialog Title")
	.setMessage("PrettyDialog Message")
	.show();
Output:

alt text

Change Icon:

  • You can set the dialog icon resource:
.setIcon(R.drawable.pdlg_icon_info)
  • And set a color tint for it:
.setIconTint(R.color.pdlg_color_green)
  • Ultimately, define an OnClick callback:
.setIconCallback(new PrettyDialogCallback() {
	    @Override
	    public void onClick() {
		// Do what you gotta do
	    }
	})
  • Put them all together:
.setIcon(
	R.drawable.pdlg_icon_info,     // icon resource
	R.color.pdlg_color_green,      // icon tint
	new PrettyDialogCallback() {   // icon OnClick listener
	    @Override
	    public void onClick() {
		// Do what you gotta do
	    }
	})
Output:

alt text

Add Buttons:

  • You can add unlimited customized buttons to dialog:
// OK button
.addButton(
		"OK",					// button text
		R.color.pdlg_color_white,		// button text color
		R.color.pdlg_color_green,		// button background color
		new PrettyDialogCallback() {		// button OnClick listener
		    @Override
		    public void onClick() {
			// Do what you gotta do
		    }
		}
	)
	
// Cancel button
.addButton(
		"Cancel",
		R.color.pdlg_color_white,
		R.color.pdlg_color_red,
		new PrettyDialogCallback() {
		    @Override
		    public void onClick() {
			// Dismiss
		    }
		}
	)
	
// 3rd button
.addButton(
		"Option 3",
		R.color.pdlg_color_black,
		R.color.pdlg_color_gray,
		null
	);
Output:

alt text

Custom Title, Message and Typeface:

Note: Typeface applies to all texts inside the dialog.

.setTitle("Do you agree?")
.setTitleColor(R.color.pdlg_color_blue)
.setMessage("By agreeing to our terms and conditions, you agree to our terms and conditions.")
.setMessageColor(R.color.pdlg_color_gray)
.setTypeface(Typeface.createFromAsset(getResources().getAssets(),"myfont.otf"))
Output:

alt text

  • Enable/Disable dialog animation:
.setAnimationEnabled(true)

Functions

Functions Description Default
setTitle(String) sets a title for dialog ""
setTitleColor(int) sets title's color #212121 (kinda black)
setMessage(String) sets a message for dialog ""
setMessageColor(int) sets message's color #212121 (kinda black)
setIcon(int) sets the dialog's icon "close (X)" icon
setIconTint(int) sets tint for dialog's icon #1976D2 (kinda blue)
setIconCallback(PrettyDialogCallback) sets dialog's icon callback dismiss dialog
setIcon(int,int,PrettyDialogCallback) sets icon,icon tint,icon callback
addButton(String,int,int,PrettyDialogCallback) adds button with text,text color,background color and callback
setTypeface(Typeface) sets typeface for all texts
setAnimationEnabled(boolean) enables or disables dialog animation Enabled

cheers ๐Ÿป

License

Copyright 2017 mjn1369

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

prettydialog's People

Contributors

mjn1369 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.