public class DialogFragment
extends Fragment implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener

   ↳ androidx.fragment.app.Fragment
     ↳ androidx.fragment.app.DialogFragment

Static library support version of the framework's DialogFragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.




Style for setStyle(int, int): a basic, normal dialog.


Style for setStyle(int, int): don't draw any frame at all; the view hierarchy returned by Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle) is entirely responsible for drawing the dialog.


Style for setStyle(int, int): like STYLE_NO_FRAME, but also disables all input to the dialog.


Style for setStyle(int, int): don't include a title area.

Public constructors


Constructor used by the default FragmentFactory.

DialogFragment(int contentLayoutId)

Alternate constructor that can be called from your default, no argument constructor to provide a default layout that will be inflated by Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle).

Public methods

void dismiss()

Dismiss the fragment and its dialog.

void dismissAllowingStateLoss()

Version of dismiss() that uses FragmentTransaction.commitAllowingStateLoss().

Dialog getDialog()

Return the Dialog this fragment is currently controlling.

boolean getShowsDialog()

Return the current value of setShowsDialog(boolean).

int getTheme()
boolean isCancelable()

Return the current value of setCancelable(boolean).

void onAttach(Context context)

Called when a fragment is first attached to its context.

void onCancel(DialogInterface dialog)
void onCreate(Bundle savedInstanceState)

Called to do initial creation of a fragment.

Dialog onCreateDialog(Bundle savedInstanceState)

Override to build your own custom Dialog container.

void onDestroyView()

Remove dialog.

void onDetach()

Called when the fragment is no longer attached to its activity.

void onDismiss(DialogInterface dialog)
LayoutInflater onGetLayoutInflater(Bundle savedInstanceState)

Returns the LayoutInflater used to inflate Views of this Fragment.

If this is called from within onCreateDialog(Bundle), the layout inflater from Fragment.onGetLayoutInflater(Bundle), without the dialog theme, will be returned.

void onSaveInstanceState(Bundle outState)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted.

void onStart()

Called when the Fragment is visible to the user.

void onStop()

Called when the Fragment is no longer started.

void onViewStateRestored(Bundle savedInstanceState)

Called when all saved state has been restored into the view hierarchy of the fragment.

final Dialog requireDialog()

Return the Dialog this fragment is currently controlling.

void setCancelable(boolean cancelable)

Control whether the shown Dialog is cancelable.

void setShowsDialog(boolean showsDialog)

Controls whether this fragment should be shown in a dialog.

void setStyle(int style, int theme)

Call to customize the basic appearance and behavior of the fragment's dialog.

void show(FragmentManager manager, String tag)

Display the dialog, adding the fragment to the given FragmentManager.

int show(FragmentTransaction transaction, String tag)

Display the dialog, adding the fragment using an existing transaction and then committing the transaction.

void showNow(FragmentManager manager, String tag)

Display the dialog, immediately adding the fragment to the given FragmentManager.

Inherited methods