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.
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 | |
---|---|
<init>() |
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 | |
open Unit |
setContentView(layoutResID: Int) |
open Unit |
setContentView(view: View!) |
open Unit |
setContentView(view: View!, params: LayoutParams!) |
open T |
findViewById(id: Int) |
open Unit | |
open Unit |
setSupportActionBar(toolbar: Toolbar?) Set a |
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 |
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 |
onConfigurationChanged(newConfig: Configuration!) |
open Boolean |
supportRequestWindowFeature(featureId: Int) Enable extended support library window features. |
open Unit | |
open Boolean |
onMenuOpened(featureId: Int, : Menu!) Please note: AppCompat uses its own feature id for the action bar: |
open Boolean |
dispatchKeyEvent(event: KeyEvent!) |
open Boolean |
supportShouldUpRecreateTask(targetIntent: Intent) Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent. |
open Unit |
onPanelClosed(featureId: Int, : Menu!) Please note: AppCompat uses its own feature id for the action bar: |
open Unit |
onCreateSupportNavigateUpTaskStack(: TaskStackBuilder) Support version of #onCreateNavigateUpTaskStack(android. |
Boolean |
onMenuItemSelected(featureId: Int, item: MenuItem!) |
open Unit | |
open Unit |
setSupportProgressBarIndeterminate(indeterminate: Boolean) |
open MenuInflater! | |
open Unit |
setSupportProgressBarVisibility(visible: Boolean) |
open Unit |
Notifies the activity that a support action mode has finished. |
open Unit |
onPrepareSupportNavigateUpTaskStack(: TaskStackBuilder) Support version of #onPrepareNavigateUpTaskStack(android. |
open ActionMode? |
startSupportActionMode(callback: ActionMode.Callback) Start an action mode. |
open AppCompatDelegate | |
open ActionBar? |
Support library version of |
open Unit | |
open Unit | |
open Resources! | |
open ActionBarDrawerToggle.Delegate? | |
open Unit | |
open Unit | |
open Unit |
setSupportProgress(progress: Int) |
Protected methods | |
---|---|
open Unit |
onTitleChanged(title: CharSequence!, color: Int) |
open Unit | |
open Unit |
onSaveInstanceState(outState: Bundle!) |
open Unit |
onStop() |
open Unit | |
open Unit |
onStart() |
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. |
setContentView
open fun setContentView(view: View!, params: LayoutParams!): Unit
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(: 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!): Boolean
Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR
.
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!): Unit
Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR
.
onCreateSupportNavigateUpTaskStack
open fun onCreateSupportNavigateUpTaskStack(: 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 |
invalidateOptionsMenu
open fun invalidateOptionsMenu(): Unit
setSupportProgressBarIndeterminate
open fun setSupportProgressBarIndeterminate(indeterminate: Boolean): Unit
getMenuInflater
open fun getMenuInflater(): MenuInflater!
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(: 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?
setSupportProgressBarIndeterminateVisibility
open fun setSupportProgressBarIndeterminateVisibility(visible: Boolean): Unit
Protected methods
onTitleChanged
protected open fun onTitleChanged(title: CharSequence!, color: Int): Unit
onPostResume
protected open fun onPostResume(): Unit
onStop
protected open fun onStop(): Unit
onStart
protected open fun onStart(): Unit
onDestroy
protected open fun onDestroy(): Unit
Interfaces
Classes