Вы находитесь на странице: 1из 11

PrettyDialog (/details/1/6628)

 35 (https://github.com/mjn1369/PrettyDialog/stargazers?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=6628) 4

(https://github.com/mjn1369/PrettyDialog/watchers?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=6628)  12

(https://github.com/mjn1369/PrettyDialog/network?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=6628)  1

(https://github.com/mjn1369/PrettyDialog/issues?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=6628)

 (https://facebook.com/sharer.php?
General u=https://android-
Category
arsenal.com/details/1/6628)
Free (/free)

Tag
 (https://twitter.com/intent/twe
arsenal.com/details/1/6628&text=The%20An
Dialogs (/tag/30)

License %20Dialogs%20-%20PrettyDialog
Apache License, Version 2.0 (http://opensource.org/licenses/Apache-2.0?utm_source=android-arsenal.co

 (http://news.ycombinator.com/submitlink
m&utm_medium=referral&utm_campaign=6628)

arsenal.com/details/1/6628&t=The%20Andro
Min SDK
10 (Android 2.3.3–2.3.7 Gingerbread) (/api?level=10)

Registered
%20Dialogs%20
Jan 3, 2018

Favorites
 (https://plus.google.com/share?
5 url=https://android-
Link arsenal.com/details/1/6628)
https://github.com/mjn1369/PrettyDialog (https://github.com/mjn1369/PrettyDialog?utm_source=android-a

 (https://reddit.com/subm
rsenal.com&utm_medium=referral&utm_campaign=6628)

arsenal.com/details/1/6628&title=The%20An
See also
BannerTime (/details/1/2527)
BottomSheet (/details/1/6623) %20Dialogs%
LongPressPopup (/details/1/4689)
Panter Dialog (/details/1/4678)
DialogSheet (/details/1/6520)

Additional

Language
Java

Version
1.0.4 (Aug 1, 2018) (https://github.com/mjn1369/PrettyDialog/releases/tag/1.0.4?utm_source=android-ars
enal.com&utm_medium=referral&utm_campaign=6628)

Created
Aug 29, 2017

Updated
Aug 1, 2018

Owner
Mahmoud Jafarinejad (mjn1369) (/user/mjn1369)

Contributor
1 (https://github.com/mjn1369/PrettyDialog/graphs/contributors?utm_source=android-arsenal.com&utm_
medium=referral&utm_campaign=6628)

Activity

Badge
 Generate

Download
 Source code
 APK file

Announcement
     

PrettyDialog

Platform Android (https://github.com/mjn1369/prettydialog?utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=6628) API 10+
(https://github.com/mjn1369/prettydialog?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628) License Apache v2.0
(http://www.apache.org/licenses/LICENSE-2.0?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628) JitPack 1.0.4
(https://jitpack.io/#mjn1369/prettydialog) Android Arsenal PrettyDialog (https://android-
arsenal.com/details/1/6628)

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.4'
}

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:
(https://github.com/mjn1369/PrettyDialog/blob/master/Screenshots/1.png?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)

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:

(https://github.com/mjn1369/PrettyDialog/blob/master/Screenshots/2.png?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)

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:
(https://github.com/mjn1369/PrettyDialog/blob/master/Screenshots/3.png?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)

Note: To Dismiss PrettyDialog on a button click, you have to instantiate PrettyDialog and keep the
variable, then call dismiss() on the variable inside button's onClickListener method:

PrettyDialog pDialog = new PrettyDialog(this);


pDialog
.setTitle("PrettyDialog Title")
.setMessage("PrettyDialog Message")
.addButton(
"Cancel",
R.color.pdlg_color_white,
R.color.pdlg_color_red,
new PrettyDialogCallback() {
@Override
public void onClick() {
pDialog.dismiss();
}
}
)
.show();

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:

(https://github.com/mjn1369/PrettyDialog/blob/master/Screenshots/4.png?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)

Enable/Disable dialog animation:

.setAnimationEnabled(true)

Set dialog gravity:

.setGravity(Gravity.BOTTOM)

Functions

Functions Description Default


Functions Description Default

setTitle(String) sets a title for dialog ""

#212121 (kind
setTitleColor(int) sets title's color
a black)

setMessage(String) sets a message for dialog ""

#212121 (kind
setMessageColor(int) sets message's color
a black)

setIcon(int) sets the dialog's icon "close (X)" icon

setIconTint(int) sets tint for dialog's icon null

setIconCallback(PrettyDialogCa
sets dialog's icon callback dismiss dialog
llback)

setIcon(int,int,PrettyDialogCallb
sets icon,icon tint,icon callback
ack)

addButton(String,int,int,PrettyDi adds button with text,text color,background


alogCallback) color and callback

setTypeface(Typeface) sets typeface for all texts

setAnimationEnabled(boolean) enables or disables dialog animation Enabled

sets the dialog's gravity (TOP, BOTTOM, CE Gravity.CENTE


setGravity(int)
NTER,...) R

Changelog

v1.0.4:

Removed default icon tint color

v1.0.3:

Added higher level scrollable content to include long messages

v1.0.2:

More Compatible setTint() method

v1.0.1:

Added "setGravity(int gravity)" method

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.

Follow us on Twitter (https://twitter.com/Android_Arsenal?utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=6628)

Read us in Telegram (https://telegram.me/AndroidArsenal?utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=6628)

Get Android app on Google Play (https://play.google.com/store/apps/details?


id=com.android_arsenal.androidarsenal&utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)

Stay informed with Pushbullet (https://www.pushbullet.com/channel?tag=android_arsenal&utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=6628)

Created by Vladislav Bauer (https://github.com/vbauer?utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=6628)
 (https://twitter.com/BauerVlad?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)
 (https://www.linkedin.com/in/vladislavbauer?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)
 (https://www.paypal.me/VladislavBauer?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=6628)
© 2014-2018 - Android Arsenal (/) | Privacy (/privacy)

Вам также может понравиться