Class DynamicDialog
java.lang.Object
android.app.Dialog
androidx.activity.ComponentDialog
androidx.appcompat.app.AppCompatDialog
com.pranavpandey.android.dynamic.support.dialog.DynamicDialog
- All Implemented Interfaces:
DialogInterface,KeyEvent.Callback,View.OnCreateContextMenuListener,Window.Callback,OnBackPressedDispatcherOwner,AppCompatCallback,LifecycleOwner,androidx.savedstate.SavedStateRegistryOwner
A subclass of Dialog that can display one, two or three buttons. If you only want to
display a String in this dialog box, use the setMessage() method. If you
want to display a more complex view, look up the FrameLayout called "custom"
and add your view to it:
FrameLayout fl = findViewById(android.R.id.custom); fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
The DynamicDialog class takes care of automatically setting
android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM for you based on whether
any views in the dialog return true from View.onCheckIsTextEditor(). Generally you want this set for a Dialog
without text editors, so that it will be placed on top of the current
input method UI. You can modify this behavior by forcing the flag to your
desired mode after calling onCreate(android.os.Bundle).
Developer Guides
For more information about creating dialogs, read the Dialogs developer guide.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface android.content.DialogInterface
DialogInterface.OnCancelListener, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, DialogInterface.OnKeyListener, DialogInterface.OnMultiChoiceClickListener, DialogInterface.OnShowListener -
Field Summary
Fields inherited from interface android.content.DialogInterface
BUTTON_NEGATIVE, BUTTON_NEUTRAL, BUTTON_POSITIVE, BUTTON1, BUTTON2, BUTTON3 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDynamicDialog(Context context) protectedDynamicDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) Construct an DynamicDialog that uses an explicit theme.protectedDynamicDialog(Context context, int themeResId) Construct an DynamicDialog that uses an explicit theme. -
Method Summary
Modifier and TypeMethodDescriptiongetButton(int whichButton) Gets one of the buttons used in the dialog.Gets the list view used in the dialog.getView()Get the view displayed in the dialog.protected voidbooleanbooleanvoidsetButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener) Sets a listener to be invoked when the positive button of the dialog is pressed.voidsetButton(int whichButton, CharSequence text, Drawable icon, DialogInterface.OnClickListener listener) Sets an icon to be displayed along with the button text and a listener to be invoked when the positive button of the dialog is pressed.voidsetButton(int whichButton, CharSequence text, Message msg) Sets a message to be sent when a button is pressed.voidsetCustomTitle(View customTitleView) This method has no effect if called afterDialog.show().voidsetIcon(int resId) Set resId to 0 if you don't want an icon.voidSet theDrawableto be used in the title.voidsetIconAttribute(int attrId) Sets an icon as supplied by a theme attribute.voidsetMessage(CharSequence message) Sets the message to display.voidsetTitle(CharSequence title) voidSet the view to display in the dialog.voidsetView(View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom) Set the view to display in the dialog, specifying the spacing to appear around that view.voidsetViewRoot(View viewRoot) Set the view root to add scroll indicators if the content can be scrolled.Methods inherited from class androidx.appcompat.app.AppCompatDialog
addContentView, dismiss, dispatchKeyEvent, findViewById, getDelegate, getSupportActionBar, invalidateOptionsMenu, onStop, onSupportActionModeFinished, onSupportActionModeStarted, onWindowStartingSupportActionMode, setContentView, setContentView, setContentView, setTitle, supportRequestWindowFeatureMethods inherited from class androidx.activity.ComponentDialog
getLifecycle, getOnBackPressedDispatcher, getSavedStateRegistry, initializeViewTreeOwners, onBackPressed, onSaveInstanceState, onStartMethods inherited from class android.app.Dialog
cancel, closeOptionsMenu, create, dispatchGenericMotionEvent, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, getActionBar, getContext, getCurrentFocus, getLayoutInflater, getOnBackInvokedDispatcher, getOwnerActivity, getSearchEvent, getVolumeControlStream, getWindow, hide, isShowing, onActionModeFinished, onActionModeStarted, onAttachedToWindow, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateOptionsMenu, onCreatePanelMenu, onCreatePanelView, onDetachedFromWindow, onGenericMotionEvent, onKeyLongPress, onKeyMultiple, onKeyShortcut, onMenuItemSelected, onMenuOpened, onOptionsItemSelected, onOptionsMenuClosed, onPanelClosed, onPrepareOptionsMenu, onPreparePanel, onRestoreInstanceState, onSearchRequested, onSearchRequested, onTouchEvent, onTrackballEvent, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, onWindowStartingActionMode, openContextMenu, openOptionsMenu, registerForContextMenu, requestWindowFeature, requireViewById, setCancelable, setCanceledOnTouchOutside, setCancelMessage, setDismissMessage, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setOnCancelListener, setOnDismissListener, setOnKeyListener, setOnShowListener, setOwnerActivity, setVolumeControlStream, show, takeKeyEvents, unregisterForContextMenuMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface android.content.DialogInterface
cancel, dismissMethods inherited from interface android.view.Window.Callback
onPointerCaptureChanged, onProvideKeyboardShortcuts
-
Constructor Details
-
DynamicDialog
-
DynamicDialog
Construct an DynamicDialog that uses an explicit theme. The actual style that an DynamicDialog uses is a private implementation, however you can here supply either the name of an attribute in the theme from which to get the dialog's style (such asR.attr.alertDialogTheme.- Parameters:
context- The context for the dialog.themeResId- The theme resource id fo the dialog.
-
DynamicDialog
protected DynamicDialog(@NonNull Context context, boolean cancelable, @Nullable DialogInterface.OnCancelListener cancelListener) Construct an DynamicDialog that uses an explicit theme. The actual style that an DynamicDialog uses is a private implementation, however you can here supply either the name of an attribute in the theme from which to get the dialog's style (such asR.attr.alertDialogTheme.- Parameters:
context- The context for the dialog.cancelable-trueto set the dialog cancelable.cancelListener- The cancel listener to be set.
-
-
Method Details
-
getButton
Gets one of the buttons used in the dialog. Returns null if the specified button does not exist or the dialog has not yet been fully created (for example, viaDialog.show()orDialog.create()).- Parameters:
whichButton- The identifier of the button that should be returned. For example, this can beDialogInterface.BUTTON_POSITIVE.- Returns:
- The button from the dialog, or null if a button does not exist.
-
getListView
Gets the list view used in the dialog.- Returns:
- The
ListViewfrom the dialog.
-
setTitle
- Overrides:
setTitlein classAppCompatDialog
-
setCustomTitle
This method has no effect if called afterDialog.show().- Parameters:
customTitleView- The custom title view for the dialog.- See Also:
-
setMessage
Sets the message to display.- Parameters:
message- The message to display in the dialog.
-
getView
Get the view displayed in the dialog. -
setView
Set the view to display in the dialog. This method has no effect if called afterDialog.show().- Parameters:
view- The view to show in the content area of the dialog.
-
setView
public void setView(@Nullable View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom) Set the view to display in the dialog, specifying the spacing to appear around that view. This method has no effect if called afterDialog.show().- Parameters:
view- The view to show in the content area of the dialogviewSpacingLeft- Extra space to appear to the left ofviewviewSpacingTop- Extra space to appear aboveviewviewSpacingRight- Extra space to appear to the right ofviewviewSpacingBottom- Extra space to appear belowview
-
setViewRoot
Set the view root to add scroll indicators if the content can be scrolled.This method has no effect if called after
Dialog.show().- Parameters:
viewRoot- The view root to be set.
-
setButton
Sets a message to be sent when a button is pressed. This method has no effect if called afterDialog.show().- Parameters:
whichButton- Which button to set the message for, can be one ofDialogInterface.BUTTON_POSITIVE,DialogInterface.BUTTON_NEGATIVE, orDialogInterface.BUTTON_NEUTRALtext- The text to display in positive button.msg- TheMessageto be sent when clicked.
-
setButton
Sets a listener to be invoked when the positive button of the dialog is pressed. This method has no effect if called afterDialog.show().- Parameters:
whichButton- Which button to set the listener on, can be one ofDialogInterface.BUTTON_POSITIVE,DialogInterface.BUTTON_NEGATIVE, orDialogInterface.BUTTON_NEUTRALtext- The text to display in positive button.listener- TheDialogInterface.OnClickListenerto use.
-
setButton
public void setButton(int whichButton, CharSequence text, Drawable icon, DialogInterface.OnClickListener listener) Sets an icon to be displayed along with the button text and a listener to be invoked when the positive button of the dialog is pressed. This method has no effect if called afterDialog.show().- Parameters:
whichButton- Which button to set the listener on, can be one ofDialogInterface.BUTTON_POSITIVE,DialogInterface.BUTTON_NEGATIVE, orDialogInterface.BUTTON_NEUTRALtext- The text to display in positive button.listener- TheDialogInterface.OnClickListenerto use.icon- TheDrawableto be set as an icon for the button.
-
setIcon
public void setIcon(int resId) Set resId to 0 if you don't want an icon.- Parameters:
resId- the resourceId of the drawable to use as the icon or 0 if you don't want an icon.
-
setIcon
Set theDrawableto be used in the title.- Parameters:
icon- Drawable to use as the icon or null if you don't want an icon.
-
setIconAttribute
public void setIconAttribute(int attrId) Sets an icon as supplied by a theme attribute. e.g. android.R.attr.alertDialogIcon- Parameters:
attrId- ID of a theme attribute that points to a drawable resource.
-
onCreate
- Overrides:
onCreatein classAppCompatDialog
-
onKeyDown
- Specified by:
onKeyDownin interfaceKeyEvent.Callback- Overrides:
onKeyDownin classDialog
-
onKeyUp
- Specified by:
onKeyUpin interfaceKeyEvent.Callback- Overrides:
onKeyUpin classDialog
-