AppCompatActivity

open class AppCompatActivity : AppCompatCallback, ActionBarDrawerToggle.DelegateProvider
kotlin.Any
   ↳ androidx.appcompat.app.AppCompatActivity

Base class for activities that use the support library action bar features.

You can add an androidx.appcompat.app.ActionBar to your activity when running on API level 7 or higher by extending this class for your activity and setting the activity theme to androidx.appcompat.R.style#Theme_AppCompat or a similar theme.

Developer Guides

For information about how to use the action bar, including how to add action items, navigation modes and more, read the Action Bar API guide.

Summary

Public constructors

Public methods
open Boolean

This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar.

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

open Unit
setContentView(layoutResID: Int)

open Unit

open Unit
setContentView(view: View!, params: LayoutParams!)

open T

open Unit

open Unit

Set a Toolbar to act as the androidx.appcompat.app.ActionBar for this Activity window.

open Unit

Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process.

open Unit
addContentView(view: View!, params: LayoutParams!)

open Intent?

Obtain an android.content.Intent that will launch an explicit target activity specified by sourceActivity's androidx.core.app.NavUtils#PARENT_ACTIVITY <meta-data> element in the application's manifest.

open ActionMode?

Called when a support action mode is being started for this window.

open Unit

open Unit

Notifies the Activity that a support action mode has been started.

open Unit

open Boolean

Enable extended support library window features.

open Unit

open Boolean
onMenuOpened(featureId: Int, menu: Menu!)

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

open Boolean

open Boolean

Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

open Unit
onPanelClosed(featureId: Int, menu: Menu!)

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

open Unit
onCreateSupportNavigateUpTaskStack(builder: TaskStackBuilder)

Support version of #onCreateNavigateUpTaskStack(android.

Boolean
onMenuItemSelected(featureId: Int, item: MenuItem!)

open Unit

open Unit

open MenuInflater!

open Unit

open Unit

Notifies the activity that a support action mode has finished.

open Unit
onPrepareSupportNavigateUpTaskStack(builder: TaskStackBuilder)

Support version of #onPrepareNavigateUpTaskStack(android.

open ActionMode?

Start an action mode.

open AppCompatDelegate

open ActionBar?

Support library version of android.app.Activity#getActionBar.

open Unit

open Unit

open Resources!

open ActionBarDrawerToggle.Delegate?

open Unit
setTheme(resid: Int)

open Unit

open Unit

Protected methods
open Unit
onTitleChanged(title: CharSequence!, color: Int)

open Unit

open Unit

open Unit

open Unit
onCreate(savedInstanceState: Bundle?)

open Unit

open Unit
onPostCreate(savedInstanceState: Bundle?)

open Unit

Public constructors

<init>

AppCompatActivity()

Public methods

onSupportNavigateUp

open fun onSupportNavigateUp(): Boolean

This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar.

If a parent was specified in the manifest for this activity or an activity-alias to it, default Up navigation will be handled automatically. See #getSupportParentActivityIntent() for how to specify the parent. If any activity along the parent chain requires extra Intent arguments, the Activity subclass should override the method #onPrepareSupportNavigateUpTaskStack(androidx.core.app.TaskStackBuilder) to supply those arguments.

See Tasks and Back Stack from the developer guide and Navigation from the design guide for more information about navigating within your app.

See the androidx.core.app.TaskStackBuilder class and the Activity methods #getSupportParentActivityIntent(), #supportShouldUpRecreateTask(android.content.Intent), and #supportNavigateUpTo(android.content.Intent) for help implementing custom Up navigation.

Return
Boolean: true if Up navigation completed successfully and this Activity was finished, false otherwise.

onKeyDown

open fun onKeyDown(keyCode: Int, event: KeyEvent!): Boolean

setContentView

open fun setContentView(layoutResID: Int): Unit

setContentView

open fun setContentView(view: View!): Unit

setContentView

open fun setContentView(view: View!, params: LayoutParams!): Unit

findViewById

open fun <T : View!> findViewById(id: Int): T

openOptionsMenu

open fun openOptionsMenu(): Unit

setSupportActionBar

open fun setSupportActionBar(toolbar: Toolbar?): Unit

Set a Toolbar to act as the androidx.appcompat.app.ActionBar for this Activity window.

When set to a non-null value the #getActionBar() method will return an androidx.appcompat.app.ActionBar object that can be used to control the given toolbar as if it were a traditional window decor action bar. The toolbar's menu will be populated with the Activity's options menu and the navigation button will be wired through the standard home menu select action.

In order to use a Toolbar within the Activity's window content the application must not request the window feature FEATURE_SUPPORT_ACTION_BAR.

Parameters
toolbar Toolbar?: Toolbar to set as the Activity's action bar, or null to clear it

supportNavigateUpTo

open fun supportNavigateUpTo(upIntent: Intent): Unit

Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP set by this method, along with any others required for proper up navigation as outlined in the Android Design Guide.

This method should be used when performing up navigation from within the same task as the destination. If up navigation should cross tasks in some cases, see #supportShouldUpRecreateTask(android.content.Intent).

Parameters
upIntent Intent: An intent representing the target destination for up navigation

addContentView

open fun addContentView(view: View!, params: LayoutParams!): Unit

getSupportParentActivityIntent

open fun getSupportParentActivityIntent(): Intent?

Obtain an android.content.Intent that will launch an explicit target activity specified by sourceActivity's androidx.core.app.NavUtils#PARENT_ACTIVITY <meta-data> element in the application's manifest. If the device is running Jellybean or newer, the android:parentActivityName attribute will be preferred if it is present.

Return
Intent?: a new Intent targeting the defined parent activity of sourceActivity

onWindowStartingSupportActionMode

open fun onWindowStartingSupportActionMode(callback: ActionMode.Callback): ActionMode?

Called when a support action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all.

Parameters
callback ActionMode.Callback: Callback to control the lifecycle of this action mode
Return
ActionMode?: The ActionMode that was started, or null if the system should present it

onSupportContentChanged

open fun onSupportContentChanged(): Unit

onSupportActionModeStarted

open fun onSupportActionModeStarted(mode: ActionMode): Unit

Notifies the Activity that a support action mode has been started. Activity subclasses overriding this method should call the superclass implementation.

Parameters
mode ActionMode: The new action mode.

onConfigurationChanged

open fun onConfigurationChanged(newConfig: Configuration!): Unit

supportRequestWindowFeature

open fun supportRequestWindowFeature(featureId: Int): Boolean

Enable extended support library window features.

This is a convenience for calling getWindow().requestFeature().

Parameters
featureId Int: The desired feature as defined in android.view.Window or androidx.core.view.WindowCompat.
Return
Boolean: Returns true if the requested feature is supported and now enabled.

supportInvalidateOptionsMenu

open fun supportInvalidateOptionsMenu(): Unit

onMenuOpened

open fun onMenuOpened(featureId: Int, menu: Menu!): Boolean

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

dispatchKeyEvent

open fun dispatchKeyEvent(event: KeyEvent!): Boolean

supportShouldUpRecreateTask

open fun supportShouldUpRecreateTask(targetIntent: Intent): Boolean

Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

If this method returns false the app can trivially call #supportNavigateUpTo(android.content.Intent) using the same parameters to correctly perform up navigation. If this method returns false, the app should synthesize a new task stack by using androidx.core.app.TaskStackBuilder or another similar mechanism to perform up navigation.

Parameters
targetIntent Intent: An intent representing the target destination for up navigation
Return
Boolean: true if navigating up should recreate a new task stack, false if the same task should be used for the destination

onPanelClosed

open fun onPanelClosed(featureId: Int, menu: Menu!): Unit

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

onCreateSupportNavigateUpTaskStack

open fun onCreateSupportNavigateUpTaskStack(builder: TaskStackBuilder): Unit

Support version of #onCreateNavigateUpTaskStack(android.app.TaskStackBuilder). This method will be called on all platform versions. Define the synthetic task stack that will be generated during Up navigation from a different task.

The default implementation of this method adds the parent chain of this activity as specified in the manifest to the supplied androidx.core.app.TaskStackBuilder. Applications may choose to override this method to construct the desired task stack in a different way.

This method will be invoked by the default implementation of #onNavigateUp() if #shouldUpRecreateTask(android.content.Intent) returns true when supplied with the intent returned by #getParentActivityIntent().

Applications that wish to supply extra Intent parameters to the parent stack defined by the manifest should override #onPrepareSupportNavigateUpTaskStack(androidx.core.app.TaskStackBuilder).

Parameters
builder TaskStackBuilder: An empty TaskStackBuilder - the application should add intents representing the desired task stack

onMenuItemSelected

fun onMenuItemSelected(featureId: Int, item: MenuItem!): Boolean

invalidateOptionsMenu

open fun invalidateOptionsMenu(): Unit

setSupportProgressBarIndeterminate

open fun setSupportProgressBarIndeterminate(indeterminate: Boolean): Unit

getMenuInflater

open fun getMenuInflater(): MenuInflater!

setSupportProgressBarVisibility

open fun setSupportProgressBarVisibility(visible: Boolean): Unit

onSupportActionModeFinished

open fun onSupportActionModeFinished(mode: ActionMode): Unit

Notifies the activity that a support action mode has finished. Activity subclasses overriding this method should call the superclass implementation.

Parameters
mode ActionMode: The action mode that just finished.

onPrepareSupportNavigateUpTaskStack

open fun onPrepareSupportNavigateUpTaskStack(builder: TaskStackBuilder): Unit

Support version of #onPrepareNavigateUpTaskStack(android.app.TaskStackBuilder). This method will be called on all platform versions. Prepare the synthetic task stack that will be generated during Up navigation from a different task.

This method receives the androidx.core.app.TaskStackBuilder with the constructed series of Intents as generated by #onCreateSupportNavigateUpTaskStack(androidx.core.app.TaskStackBuilder). If any extra data should be added to these intents before launching the new task, the application should override this method and add that data here.

Parameters
builder TaskStackBuilder: A TaskStackBuilder that has been populated with Intents by onCreateNavigateUpTaskStack.

startSupportActionMode

open fun startSupportActionMode(callback: ActionMode.Callback): ActionMode?

Start an action mode.

Parameters
callback ActionMode.Callback: Callback that will manage lifecycle events for this context mode
Return
ActionMode?: The ContextMode that was started, or null if it was canceled

getDelegate

open fun getDelegate(): AppCompatDelegate
Return
AppCompatDelegate: The AppCompatDelegate being used by this Activity.

getSupportActionBar

open fun getSupportActionBar(): ActionBar?

Support library version of android.app.Activity#getActionBar.

Retrieve a reference to this activity's ActionBar.

Return
ActionBar?: The Activity's ActionBar, or null if it does not have one.

onContentChanged

open fun onContentChanged(): Unit

closeOptionsMenu

open fun closeOptionsMenu(): Unit

getResources

open fun getResources(): Resources!

getDrawerToggleDelegate

open fun getDrawerToggleDelegate(): ActionBarDrawerToggle.Delegate?

setTheme

open fun setTheme(resid: Int): Unit

setSupportProgressBarIndeterminateVisibility

open fun setSupportProgressBarIndeterminateVisibility(visible: Boolean): Unit

setSupportProgress

open fun setSupportProgress(progress: Int): Unit

Protected methods

onTitleChanged

protected open fun onTitleChanged(title: CharSequence!, color: Int): Unit

onPostResume

protected open fun onPostResume(): Unit

onSaveInstanceState

protected open fun onSaveInstanceState(outState: Bundle!): Unit

onStop

protected open fun onStop(): Unit

onCreate

protected open fun onCreate(savedInstanceState: Bundle?): Unit

onStart

protected open fun onStart(): Unit

onPostCreate

protected open fun onPostCreate(savedInstanceState: Bundle?): Unit

onDestroy

protected open fun onDestroy(): Unit