Advanced dialog solution for android

Overview

Android Arsenal API Join the chat at https://gitter.im/orhanobut/dialogplus

DialogPlus

Simple and advanced dialog solution.

  • Uses normal view as dialog
  • Provides expandable option
  • Multiple positioning
  • Built-in options for easy implementation

DialogPlus provides android L dialog animation
DialogPlus provides 3 position:
  • Top : Dialog will appear at top with animation
  • Center : Dialog will appear in the center with animation
  • Bottom : Dialog will appear at the bottom of the screen with animation
DialogPlus provides 3 content types:
  • ListHolder : Items will be shown in a listview
  • GridHolder : Items will be shown in a gridview
  • ViewHolder : Your customized view will be shown in the content

Gradle

implementation 'com.orhanobut:dialogplus:1.11@aar'

Usage

Use the builder to create the dialog.

Basic usage

DialogPlus dialog = DialogPlus.newDialog(this)
  .setAdapter(adapter)
  .setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
    }
  })
  .setExpanded(true)  // This will enable the expand feature, (similar to android L share dialog)
  .create();
dialog.show();

More options

Enable expand animation same as Android L share dialog

.setExpanded(true) // default is false, only works for grid and list

Set expand animation default height

.setExpanded(true, 300)

Select different holder.

  • Use ListView as content holder, note that this is default content type.
setContentHolder(new ListHolder())
  • Use ViewHolder as content holder if you want to use a custom view for your dialog. Pass resource id
.setContentHolder(new ViewHolder(R.layout.content))

or pass view itself

.setContentHolder(new ViewHolder(view))
  • Use GridHolder if you want to use GridView for the dialog. You must set column number.
.setContentHolder(new GridHolder(COLUMN_NUMBER))
  • Get the holder view, ListView, GridView or your custom view
View view = dialogPlus.getHolderView();
  • Set dialog position. BOTTOM (default), TOP or CENTER. You can also combine other Gravity options.
.setGravity(Gravity.CENTER)
  • Define if the dialog is cancelable and should be closed when back pressed or out of dialog is clicked
.setCancelable(true)
  • Set Adapter, this adapter will be used to fill the content for ListHolder and GridHolder. This is required if the content holder is ListHolder or GridHolder. It is not required if the content holder is ViewHolder.
.setAdapter(adapter);
  • Set an item click listener when list or grid holder is chosen. In that way you can have callbacks when one of your items is clicked
.setOnItemClickListener(new OnItemClickListener() {
  @Override
  public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
  }
})
  • Set a global click listener to you dialog in order to handle all the possible click events. You can then identify the view by using its id and handle the correct behaviour. Only views which has id will trigger this event.
.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(DialogPlus dialog, View view) {

    }
})
  • Add margins to your dialog. They are set to 0 except when gravity is center. In that case basic margins are applied
.setMargin(left, top, right, bottom)
  • Set padding to the holder
.setPadding(left, top, right, bottom)
  • Set the footer view using the id of the layout resource
.setFooter(R.layout.footer)

or use view

.setFooter(view)
  • Get the footer view
View view = dialogPlus.getFooterView();
  • Set the header view using the id of the layout resource
.setHeader(R.layout.header)

or use view

.setHeader(view)
  • Get the header view
View view = dialogPlus.getHeaderView();
  • Set animation resources
.setInAnimation(R.anim.abc_fade_in)
.setOutAnimation(R.anim.abc_fade_out)
  • Set width and height for the content
.setContentWidth(ViewGroup.LayoutParams.WRAP_CONTENT)  // or any custom width ie: 300
.setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
  • Dismiss Listener, triggered when the dialog is dismissed
.setOnDismissListener(new OnDismissListener() {
    @Override
    public void onDismiss(DialogPlus dialog) {

    }
})
  • Cancel Listener, triggered when the dialog is cancelled by back button or clicking outside
.setOnCancelListener(new OnCancelListener() {
    @Override
    public void onCancel(DialogPlus dialog) {

    }
})
  • BackPress Listener, triggered when the back button is pressed
.setOnBackPressListener(new OnBackPressListener() {
    @Override
    public void onBackPressed(DialogPlus dialog) {

    }
})
  • Change content container background, as default white
.setContentBackgroundResource(resource)
  • Change overlay container background, as default it's semi-transparent black
.setOverlayBackgroundResource(resource)

License

Copyright 2016 Orhan Obut

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.
Comments
  • Support composite gravities

    Support composite gravities

    Instead of requiring gravity to be set as just a simple value, e.g. Gravity.BOTTOM, allow composite ones which are based on TOP, BOTTOM and CENTER such as BOTTOM | CENTER_HORIZONTAL. This is achieved by a bitwise check.

    opened by Kisty 14
  • Cannot open dialog straight after closing another one?

    Cannot open dialog straight after closing another one?

    I have a function, which on success shows a dialog. However, if there is an error it will show a different dialog. If they press "OK" on the error dialog the function is recursively called and now ends in success. However the other dialog will not show, it's almost as if the old dialog isnt being dismissed in time.

    opened by broakenmedia 13
  •  Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead

    Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead

    Hi, I want to add a whellview to dialogplus, it extend from spinner. but throw a exception.

    07-25 22:13:30.493: E/AndroidRuntime(13740): java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.jyxtec.wheel.TosAdapterView.setOnClickListener(TosAdapterView.java:803) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.setClickListener(DialogPlus.java:315) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:300) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.createView(DialogPlus.java:259) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.initContentView(DialogPlus.java:227) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.(DialogPlus.java:111) 07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlusBuilder.create(DialogPlusBuilder.java:265)

    opened by wood23636 13
  • Show panel in bottom centre

    Show panel in bottom centre

    Doing DialogPlusBuilder#setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL) causes a crash because it can't work out the animation to play in #getOutAnimation(). I think it just requires a bit mask check rather than using equals.

    bug 
    opened by Kisty 10
  • Center does not work on horizontal axis

    Center does not work on horizontal axis

    Hi,

    First of all tnx very much for such clean and developer friendly library :)

    As you can be seen in attachment i could not center on horizontal axis. Does library support this functionality or did i miss something?

    Here is my code :

    final DialogPlus dialog = new DialogPlus.Builder(this)
                .setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
                        //
                    }
                })
                .setGravity(DialogPlus.Gravity.CENTER)
                .setContentHolder(isparkDetailView)
                .setCancelable(true)
                .create();
    dialog.show();
    

    screenshot-2015-06-18_15 23 07 964

    King Regards

    bug 
    opened by ergunkocak 8
  • How to Set corner for dialog ?

    How to Set corner for dialog ?

    Hello I want to set the corner for dialog but is not work? I have tried many ways but failed as set xml , GradientDrawable with DialogUpgrade.getHolderView ( ),and customize layout of View tks . Please help me

    opened by chihung93 7
  • Inside EditText

    Inside EditText

    If i add a EditText into DialogPlus,then, click editText -> pop soft keyboard -> click hardware BACK. I want DailogPlus dismiss,but whole activity finished. Is it a trouble?

    Exp: your demo R.layout.content ,replace TextView with EditText

    opened by ren545457803 6
  • Transparent black background can not be removed

    Transparent black background can not be removed

    Hello,

    Even i used :

    setBackgroundColorResourceId(R.color.transparent_color)
    

    there is still a transparent background i could change it like this :

    ((FrameLayout) findViewById(R.id.content_container).getParent()).setBackgroundColor(getResources().getColor(R.color.transparent_color))
    

    FYI

    opened by ergunkocak 5
  • Using Fragments within dialog

    Using Fragments within dialog

    Hello,

    Is there a way to use Fragments within the dialog?

    I've been trying to add a view with a FrameLayout element and calling FragmentManager methods to fetch and change views but it says something about IllegalStateException, view has already a parent or something like that.

    I'm trying to make a dialog with tabs...

    I went for TabHost but I got different problems with deprecated classes. I went for ViewPager and PagerTabStrip but it's not the UX I was required to implement. So I decided to make all by hand with Fragments but I cannot communicate with a FrameLayout for content within your dialog. The FragmentManager mess up with the hierarchy I think...

    I'd appreciate any clues about this issue.

    opened by joshuamzm 5
  • Reproducing list of apps to share in Lolipop

    Reproducing list of apps to share in Lolipop

    This pull request will resolve the issue #26. The changes may not be clear, this is just a prototype that focuses on reproducing list of apps to share in Lolipop. The options to enable it in Dialog Plus Sample are that checking List Holder, Show fixed header. After that, just click BOTTOM button.

    Remaining tasks

    • [X] alter global variables as a plain name without m prefix.
    • [ ] support backwards compatibility, currently only runnable on api >= 21.
    • [ ] give an intuitive name to the DimmedListHolder, the meaning of its name is vague.
    • [ ] add comments on related changes that play a pivotal role in presenting list of apps to share like Lolipop.
    opened by doyonghoon 5
  • Callback when the dialog has been dismissed

    Callback when the dialog has been dismissed

    As Ordinary Dialog does, DialogPlus seems like to have the listener that notifies the user when DialogPlus dismisses. mind if I push a pull request for this issue and review for my code? thanks.

    opened by doyonghoon 5
  • setOnItemClickListener is not working

    setOnItemClickListener is not working

    Main activity contains below code

       ProductRegistrationDetails productRegistrationDetails = new ProductRegistrationDetails();
                productRegistrationDetails.setActiveRegistrationFound(isActiveRegistrationFound);
                productRegistrationDetails.setNumberOfFreebies(numberOfFreebies);
                productRegistrationDetails.setNumberOfRegistrationBasedAdsPerMonth(numberOfRegistrationBasedAdsPerMonth);
                productRegistrationDetails.setRemainingProduct(remainingProduct);
                productRegistrationDetails.setTrialEnabled(isTrialEnabled);
                productRegistrationDetails.setTrialExpired(isTrialExpired);
                productRegistrationDetails.setUpgradedPackageIsUsing(isUpgradedPackageIsUsing);
                ProductRegistrationAdapter adapter = new ProductRegistrationAdapter(context, productRegistrationDetails);
    
    DialogPlus dialogPlus = DialogPlus.newDialog(this)
                        .setAdapter(adapter)
                        .setContentHolder(new ListHolder())
                        .setExpanded(true)
                        .setCancelable(true)
                        .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
                                CustomSnackBar snackBar = new CustomSnackBar(context, view, "this is test",
                                        Snackbar.LENGTH_LONG, CustomSnackBar.INFO);
                                snackBar.show();
                            }
                        })
                        .create();
                dialogPlus.show();
    

    My Adapter Class

    public class ProductRegistrationAdapter extends BaseAdapter {
    
        private static final String TAG = ProductRegistrationAdapter.class.getSimpleName();
        private Context mContext;
    
    
        private ProductRegistrationDetails productRegistrationDetails;
    
        public ProductRegistrationAdapter(@NonNull Context context, ProductRegistrationDetails details) {
            this.mContext = context;
            productRegistrationDetails = details;
        }
    
        @Override
        public int getCount() {
            return 1;
        }
    
        @Override
        public Object getItem(int i) {
            return i;
        }
    
        @Override
        public long getItemId(int i) {
            return i;
        }
    
        @Override
        public View getView(final int i, View view, ViewGroup viewGroup) {
            ProductRegistrationAdapter.ViewHolder holder;
            if (view == null) {
                LayoutInflater inflater = (LayoutInflater) mContext
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = inflater.inflate(R.layout.registration_dialog, viewGroup, false);
                holder = new ProductRegistrationAdapter.ViewHolder();
                holder.registerNow = (Button) view.findViewById(R.id.register_now);
                holder.info = (TextView) view.findViewById(R.id.dialog_info);
                view.setTag(holder);
    
            } else {
                holder = (ProductRegistrationAdapter.ViewHolder) view.getTag();
            }
            return view;
    
        }
    
        private static class ViewHolder {
            TextView info;
            TextView Id;
            Button registerNow;
        }
    }
    
    
    opened by itsmeJithin 0
  • textbox settext not updating before dialog load

    textbox settext not updating before dialog load

    Hi, I need to access the elements to settext of a textbox or a set a checkbox before the dialog loads it works fine when i use the code below in the activity to set the text but does not work in a fragment inside a tabLayout in Activity: ` View view = getLayoutInflater().inflate(R.layout.fragment_agent, null); TextView agencyTitle = (TextView) view.findViewById(R.id.agencyTitleTextView);

         executor.execute(new Runnable() {
                                        @Override
                                        public void run() {
                            agencyTitle.setText(agent.getAgencyTitle());
    

    } }); DialogPlus dialog = DialogPlus.newDialog(ListingViewActivity.this) ....but when i use it in a fragment when i log the result it seems to gets the value but it **does not refresh the layout** and see the values !!! in fragment:View myView = LayoutInflater.from(getContext()).inflate(R.layout.fragment_agent, null);

    executor.execute(new Runnable() { @Override public void run() { CheckBox chk1 = (CheckBox) myView.findViewById(R.id.checkbox_apartment); chk1.setChecked(true);`

    what is wrong here!?

    opened by keyvan1361 0
  • Customization

    Customization

    Is it possible to customize the popover by giving it the border radius ?

    Do that library have long press(press on a button during 2 seconds for exapmle) feature before showing the popover ?

    Thanks.

    opened by BoumBam 1
Releases(1.11)
  • 1.11(Jan 31, 2016)

    • padding top issue fix for utils
    • setContentBackgroundResource added, as default white
    • setOverlayBackgroundResource added, as default semi-transparent black
    • ListViewHolder itemclick position will return 0 when there is header (it was 1)
    Source code(tar.gz)
    Source code(zip)
  • v1.10(Jul 18, 2015)

  • v1.9(Jul 12, 2015)

  • v1.8(Jul 12, 2015)

    • Set content width and height manually
    .setContentWidth(800)
    .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
    
    • Set default height when expand feature is enabled
    .setExpanded(true, 100)
    
    • Major change for the builder class. DialogPlus must use new static factory method to initialize.
    DialogPlus dialog = DialogPlus.newDialog(context) ...
    
    • Major refactoring
    Source code(tar.gz)
    Source code(zip)
  • v1.7(Jun 21, 2015)

    • Expand feature added similar to Android L share dialog.
    .setExpanded(true);    //this will enable it
    
    • ScreenType removed
    • Gravity now uses android gravity class.
    Source code(tar.gz)
    Source code(zip)
  • v1.6(May 22, 2015)

  • v1.5-release(Apr 11, 2015)

    • getHeaderView() added
    • getFooterView() added
    • getHolderView() added
    • some bug fixes
    • OnCancelListener added
    • OnDismissListener added
    • OnBackPressListener added
    Source code(tar.gz)
    Source code(zip)
  • v1.2(Feb 1, 2015)

    • BasicHolder is removed
    • ViewHolder added in order to add custom view.
    • Top, Center animations are added
    • Center option is added
    • Set margin option is added
    • Set animation option is added
    • OnClickListener option is added
    Source code(tar.gz)
    Source code(zip)
  • v1.1(Jan 21, 2015)

    • OnItemClickListener modified, it contains DialogPlus object now.
    • Backpress issue is fixed, it will dismiss the dialog if the cancelable is true
    Source code(tar.gz)
    Source code(zip)
Owner
Orhan Obut
Architect | ex Android GDE
Orhan Obut
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.

# Media Recorder Dialog ![](https://img.shields.io/badge/Platform-Android-brightgreen.svg) ![](https://img.shields.io/badge/Android-CustomView-blue.sv

Abdullah Alhazmy 73 Nov 29, 2022
ionalert 1.3 1.6 Java Sweetalert, Dialog, Alert Dialog

ionalert - Android Alert Dialog A beautiful design Android Alert Dialog, alternative of Sweet Alert Dialog based on KAlertDialog using MaterialCompone

Excel Dwi Oktavianto 23 Sep 17, 2022
Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.

We show a warning message (Alert Dialog) to the user in many parts of our applications. You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment. Thanks to this extension, you can create a Dialog and call it in the Activity or Fragment you want and customize the component you want.

Gökmen Bayram 0 Jan 9, 2022
AlertDialog for Android, a beautiful and material alert dialog to use in your android app.

AlertDialog for Android, a beautiful and material alert dialog to use in your android app. Older verion of this library has been removed

Akshay Masram 124 Dec 28, 2022
SweetAlert for Android, a beautiful and clever alert dialog

Sweet Alert Dialog SweetAlert for Android, a beautiful and clever alert dialog 中文版 Inspired by JavaScript SweetAlert Demo Download ScreenShot Setup Th

书呆子 7.3k Dec 30, 2022
An Android Dialog Lib simplify customization.

FlycoDialog-Master 中文版 An Android Dialog Lib simplify customization. Supprot 2.2+. Features [Built-in Dialog, convenient to use](#Built-in Dialog) [Ab

Flyco 2.3k Dec 8, 2022
[Deprecated] This project can make it easy to theme and custom Android's dialog. Also provides Holo and Material themes for old devices.

Deprecated Please use android.support.v7.app.AlertDialog of support-v7. AlertDialogPro Why AlertDialogPro? Theming Android's AlertDialog is not an eas

Feng Dai 468 Nov 10, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
A simple file/ directory picker dialog for android

FileListerDialog FileListerDialog helps you to list and pick file/directory. Library is built for Android Getting Started Installing To use this libra

Yogesh S 446 Jan 7, 2023
a quick custom android dialog project

QustomDialog Qustom helps you make quick custom dialogs for Android. All this is, for the time being, is a way to make it easy to achieve the Holo loo

Daniel Smith 183 Nov 20, 2022
Android library that allows applications to add dialog-based slider widgets to their settings

Android Slider Preference Library Overview Slider represents a float between 0.0 and 1.0 Access with SliderPreference.getValue() or SharedPreferences.

Jay Petacat 135 Nov 29, 2022
An Android library for displaying a dialog where it presents new features in the app.

WhatIsNewDialog What is new dialog for Android is used for presenting new features in the the app. It can be used in the activity starts, from menu or

NonZeroApps 22 Aug 23, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
A simple library to show custom dialog with animation in android

SmartDialog A simple library to show custom dialog in android Step 1. Add the JitPack repository to your build file allprojects { repositories {

claudysoft 9 Aug 18, 2022
AlertDialog - Explain about Alert Dialog in Android

AndroidTemplate I got a problem to create Android project with Java 11 and anoth

Monthira Chayabanjonglerd 1 Feb 13, 2022
An beautiful and easy to use dialog library for Android

An beautiful and easy to use dialog library for Android

ShouHeng 22 Nov 8, 2022
CuteDialog- Android Custom Material Dialog Library

A Custom Material Design Dialog Library for Android Purpose CuteDialog is a Highly Customizable Material Design Android Library. CuteDialog allows dev

CuteLibs - Smart & Beautiful Android Libraries 7 Dec 7, 2022
An easy to use, yet very customizable search dialog

search-dialog An awesome and customizable search dialog with built-in search options. Usage First add jitpack to your projects build.gradle file allpr

Mad Mirrajabi 518 Dec 15, 2022
Common dialog fragments

Common dialog fragments

null 6 Aug 29, 2022