ComponentDialog


public class ComponentDialog extends Dialog implements LifecycleOwner, OnBackPressedDispatcherOwner, NavigationEventDispatcherOwner, SavedStateRegistryOwner

Known direct subclasses
AppCompatDialog

Base class for AppCompat themed android.app.Dialogs.

Known indirect subclasses
AlertDialog

A subclass of Dialog that can display one, two or three buttons.

MediaRouteChooserDialog

This class implements the route chooser dialog for MediaRouter.

MediaRouteControllerDialog

This class implements the route controller dialog for MediaRouter.


Base class for dialogs that enables composition of higher level components.

Summary

Public constructors

ComponentDialog(@NonNull Context context, @StyleRes int themeResId)

Public methods

void
@NonNull Lifecycle
@NonNull NavigationEventDispatcher

Lazily provides a NavigationEventDispatcher for back navigation handling, including support for predictive back gestures introduced in Android 13 (API 33+).

final @NonNull OnBackPressedDispatcher

Retrieve the OnBackPressedDispatcher that will be triggered when onBackPressed is called.

@NonNull SavedStateRegistry
void

Sets the view tree owners before setting the content view so that the inflation process and attach listeners will see them already present.

void

This method is deprecated. This method has been deprecated in favor of using the {@link OnBackPressedDispatcher} via {@link #getOnBackPressedDispatcher()}.

@NonNull Bundle
void
setContentView(int layoutResID)
void
void

Protected methods

void
@CallSuper
onCreate(Bundle savedInstanceState)
void
void

Inherited methods

From android.app.Dialog
void
void
@NonNull T
<T extends View> findViewById(int id)
@Nullable ActionBar
final @NonNull Context
@Nullable View
@NonNull LayoutInflater
@NonNull OnBackInvokedDispatcher
final @Nullable Activity
final @Nullable SearchEvent
final int
@Nullable Window
void
void
boolean
boolean
void
boolean
boolean
boolean
onKeyShortcut(int keyCode, @NonNull KeyEvent event)
boolean
void
boolean
void
onRestoreInstanceState(@NonNull Bundle savedInstanceState)
boolean
boolean
void
void
void
final boolean
requestWindowFeature(int featureId)
final @NonNull T
<T extends View> requireViewById(int id)
void
void
setCancelable(boolean flag)
void
setCanceledOnTouchOutside(boolean cancel)
void
final void
setFeatureDrawable(int featureId, @Nullable Drawable drawable)
final void
setFeatureDrawableAlpha(int featureId, int alpha)
final void
setFeatureDrawableResource(int featureId, int resId)
final void
setFeatureDrawableUri(int featureId, @Nullable Uri uri)
void
void
void
void
final void
void
void
setTitle(int titleId)
final void
setVolumeControlStream(int streamType)
void
void
takeKeyEvents(boolean get)
void
From android.content.DialogInterface
void
void
From android.view.KeyEvent.Callback
boolean
onKeyDown(int keyCode, @NonNull KeyEvent event)
boolean
onKeyLongPress(int keyCode, @NonNull KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, @NonNull KeyEvent event)
boolean
onKeyUp(int keyCode, @NonNull KeyEvent event)
From android.view.View.OnCreateContextMenuListener
void
From android.view.Window.Callback
boolean
boolean
boolean
boolean
boolean
boolean
void
void
void
void
boolean
onCreatePanelMenu(int featureId, @NonNull Menu menu)
View
onCreatePanelView(int featureId)
void
boolean
onMenuItemSelected(int featureId, @NonNull MenuItem item)
boolean
onMenuOpened(int featureId, @NonNull Menu menu)
void
onPanelClosed(int featureId, @NonNull Menu menu)
void
onPointerCaptureChanged(boolean hasCapture)
boolean
onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu)
void
onProvideKeyboardShortcuts(
    @NonNull List<@NonNull KeyboardShortcutGroup> data,
    @Nullable Menu menu,
    int deviceId
)
boolean
boolean
void
void
onWindowFocusChanged(boolean hasFocus)
ActionMode
ActionMode
onWindowStartingActionMode(
    @NonNull ActionMode.Callback callback,
    int type
)

Public constructors

ComponentDialog

Added in 1.5.0
public ComponentDialog(@NonNull Context context, @StyleRes int themeResId)

Public methods

addContentView

public void addContentView(@NonNull View view, ViewGroup.LayoutParams params)

getLifecycle

Added in 1.5.0
public @NonNull Lifecycle getLifecycle()

getNavigationEventDispatcher

Added in 1.12.0
public @NonNull NavigationEventDispatcher getNavigationEventDispatcher()

Lazily provides a NavigationEventDispatcher for back navigation handling, including support for predictive back gestures introduced in Android 13 (API 33+).

This dispatcher acts as the central point for back navigation events. When a navigation event occurs (e.g., a back gesture), it safely invokes ComponentDialog.onBackPressed.

getOnBackPressedDispatcher

public final @NonNull OnBackPressedDispatcher getOnBackPressedDispatcher()

Retrieve the OnBackPressedDispatcher that will be triggered when onBackPressed is called.

Returns
@NonNull OnBackPressedDispatcher

The OnBackPressedDispatcher associated with this ComponentDialog.

getSavedStateRegistry

Added in 1.7.0
public @NonNull SavedStateRegistry getSavedStateRegistry()

initializeViewTreeOwners

Added in 1.8.0
@CallSuper
public void initializeViewTreeOwners()

Sets the view tree owners before setting the content view so that the inflation process and attach listeners will see them already present.

onBackPressed

Added in 1.6.0
@CallSuper
public void onBackPressed()

onSaveInstanceState

public @NonNull Bundle onSaveInstanceState()

setContentView

public void setContentView(int layoutResID)

setContentView

public void setContentView(@NonNull View view)

setContentView

public void setContentView(@NonNull View view, ViewGroup.LayoutParams params)

Protected methods

onCreate

@CallSuper
protected void onCreate(Bundle savedInstanceState)

onStart

@CallSuper
protected void onStart()

onStop

@CallSuper
protected void onStop()