belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1
AppCompatActivity
public
class
AppCompatActivity
extends FragmentActivity
implements
AppCompatCallback,
TaskStackBuilder.SupportParentable,
ActionBarDrawerToggle.DelegateProvider
java.lang.Object | ||||||
↳ | android.content.Context | |||||
↳ | android.content.ContextWrapper | |||||
↳ | android.view.ContextThemeWrapper | |||||
↳ | android.app.Activity | |||||
↳ | android.support.v4.app.FragmentActivity | |||||
↳ | android.support.v7.app.AppCompatActivity |
Base class for activities that use the support library action bar features.
You can add an 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
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
Inherited constants |
---|
From
class
android.app.Activity
|
From
class
android.content.Context
|
From
interface
android.content.ComponentCallbacks2
|
Inherited fields |
---|
From
class
android.app.Activity
|
Public constructors | |
---|---|
AppCompatActivity()
|
Public methods | |
---|---|
void
|
addContentView(View view, ViewGroup.LayoutParams params)
|
void
|
closeOptionsMenu()
|
boolean
|
dispatchKeyEvent(KeyEvent event)
|
<T extends View>
T
|
findViewById(int id)
|
AppCompatDelegate
|
getDelegate()
|
ActionBarDrawerToggle.Delegate
|
getDrawerToggleDelegate()
|
MenuInflater
|
getMenuInflater()
|
Resources
|
getResources()
|
ActionBar
|
getSupportActionBar()
Support library version of |
Intent
|
getSupportParentActivityIntent()
Obtain an |
void
|
invalidateOptionsMenu()
|
void
|
onConfigurationChanged(Configuration newConfig)
Dispatch configuration change to all fragments. |
void
|
onContentChanged()
|
void
|
onCreateSupportNavigateUpTaskStack(TaskStackBuilder builder)
Support version of |
boolean
|
onKeyDown(int keyCode, KeyEvent event)
|
final
boolean
|
onMenuItemSelected(int featureId, MenuItem item)
Dispatch context and options menu to fragments. |
boolean
|
onMenuOpened(int featureId, Menu menu)
Please note: AppCompat uses its own feature id for the action bar:
|
void
|
onPanelClosed(int featureId, Menu menu)
Call onOptionsMenuClosed() on fragments. Please note: AppCompat uses its own feature id for the action bar:
|
void
|
onPrepareSupportNavigateUpTaskStack(TaskStackBuilder builder)
Support version of |
void
|
onSupportActionModeFinished(ActionMode mode)
Notifies the activity that a support action mode has finished. |
void
|
onSupportActionModeStarted(ActionMode mode)
Notifies the Activity that a support action mode has been started. |
void
|
onSupportContentChanged()
This method was deprecated
in API level 25.1.0.
Use |
boolean
|
onSupportNavigateUp()
This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar. |
ActionMode
|
onWindowStartingSupportActionMode(ActionMode.Callback callback)
Called when a support action mode is being started for this window. |
void
|
openOptionsMenu()
|
void
|
setContentView(View view)
|
void
|
setContentView(int layoutResID)
|
void
|
setContentView(View view, ViewGroup.LayoutParams params)
|
void
|
setSupportActionBar(Toolbar toolbar)
Set a |
void
|
setSupportProgress(int progress)
This method was deprecated in API level 25.1.0. Progress bars are no longer provided in AppCompat. |
void
|
setSupportProgressBarIndeterminate(boolean indeterminate)
This method was deprecated in API level 25.1.0. Progress bars are no longer provided in AppCompat. |
void
|
setSupportProgressBarIndeterminateVisibility(boolean visible)
This method was deprecated in API level 25.1.0. Progress bars are no longer provided in AppCompat. |
void
|
setSupportProgressBarVisibility(boolean visible)
This method was deprecated in API level 25.1.0. Progress bars are no longer provided in AppCompat. |
void
|
setTheme(int resid)
|
ActionMode
|
startSupportActionMode(ActionMode.Callback callback)
Start an action mode. |
void
|
supportInvalidateOptionsMenu()
This method is deprecated.
Call |
void
|
supportNavigateUpTo(Intent upIntent)
Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. |
boolean
|
supportRequestWindowFeature(int featureId)
Enable extended support library window features. |
boolean
|
supportShouldUpRecreateTask(Intent targetIntent)
Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent. |
Protected methods | |
---|---|
void
|
onCreate(Bundle savedInstanceState)
Perform initialization of all fragments. |
void
|
onDestroy()
Destroy all fragments. |
void
|
onPostCreate(Bundle savedInstanceState)
|
void
|
onPostResume()
Dispatch onResume() to fragments. |
void
|
onSaveInstanceState(Bundle outState)
Save all appropriate fragment state. |
void
|
onStart()
Dispatch onStart() to all fragments. |
void
|
onStop()
Dispatch onStop() to all fragments. |
void
|
onTitleChanged(CharSequence title, int color)
|
Public constructors
Public methods
addContentView
void addContentView (View view, ViewGroup.LayoutParams params)
Parameters | |
---|---|
view |
View |
params |
ViewGroup.LayoutParams |
closeOptionsMenu
void closeOptionsMenu ()
dispatchKeyEvent
boolean dispatchKeyEvent (KeyEvent event)
Parameters | |
---|---|
event |
KeyEvent |
Returns | |
---|---|
boolean |
findViewById
T findViewById (int id)
Parameters | |
---|---|
id |
int |
Returns | |
---|---|
T |
getDelegate
AppCompatDelegate getDelegate ()
Returns | |
---|---|
AppCompatDelegate |
The AppCompatDelegate being used by this Activity.
|
getDrawerToggleDelegate
ActionBarDrawerToggle.Delegate getDrawerToggleDelegate ()
Returns | |
---|---|
ActionBarDrawerToggle.Delegate |
getSupportActionBar
ActionBar getSupportActionBar ()
Support library version of getActionBar()
.
Retrieve a reference to this activity's ActionBar.
Returns | |
---|---|
ActionBar |
The Activity's ActionBar, or null if it does not have one. |
getSupportParentActivityIntent
Intent getSupportParentActivityIntent ()
Obtain an Intent
that will launch an explicit target activity
specified by sourceActivity's 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.
Returns | |
---|---|
Intent |
a new Intent targeting the defined parent activity of sourceActivity |
invalidateOptionsMenu
void invalidateOptionsMenu ()
onConfigurationChanged
void onConfigurationChanged (Configuration newConfig)
Dispatch configuration change to all fragments.
Parameters | |
---|---|
newConfig |
Configuration |
onContentChanged
void onContentChanged ()
onCreateSupportNavigateUpTaskStack
void onCreateSupportNavigateUpTaskStack (TaskStackBuilder builder)
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 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(android.support.v4.app.TaskStackBuilder)
.
Parameters | |
---|---|
builder |
TaskStackBuilder : An empty TaskStackBuilder - the application should add intents representing
the desired task stack
|
onKeyDown
boolean onKeyDown (int keyCode, KeyEvent event)
Parameters | |
---|---|
keyCode |
int |
event |
KeyEvent |
Returns | |
---|---|
boolean |
onMenuItemSelected
boolean onMenuItemSelected (int featureId, MenuItem item)
Dispatch context and options menu to fragments.
Parameters | |
---|---|
featureId |
int |
item |
MenuItem |
Returns | |
---|---|
boolean |
onMenuOpened
boolean onMenuOpened (int featureId, Menu menu)
Please note: AppCompat uses its own feature id for the action bar:
FEATURE_SUPPORT_ACTION_BAR
.
Parameters | |
---|---|
featureId |
int |
menu |
Menu |
Returns | |
---|---|
boolean |
onPanelClosed
void onPanelClosed (int featureId, Menu menu)
Call onOptionsMenuClosed() on fragments.
Please note: AppCompat uses its own feature id for the action bar:
FEATURE_SUPPORT_ACTION_BAR
.
Parameters | |
---|---|
featureId |
int |
menu |
Menu |
onPrepareSupportNavigateUpTaskStack
void onPrepareSupportNavigateUpTaskStack (TaskStackBuilder builder)
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 TaskStackBuilder
with the constructed series of
Intents as generated by onCreateSupportNavigateUpTaskStack(android.support.v4.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.
|
onSupportActionModeFinished
void onSupportActionModeFinished (ActionMode mode)
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.
|
onSupportActionModeStarted
void onSupportActionModeStarted (ActionMode mode)
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.
|
onSupportContentChanged
void onSupportContentChanged ()
This method was deprecated
in API level 25.1.0.
Use onContentChanged()
instead.
onSupportNavigateUp
boolean onSupportNavigateUp ()
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(android.support.v4.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 TaskStackBuilder
class and the Activity methods
getSupportParentActivityIntent()
, supportShouldUpRecreateTask(android.content.Intent)
, and
supportNavigateUpTo(android.content.Intent)
for help implementing custom Up navigation.
Returns | |
---|---|
boolean |
true if Up navigation completed successfully and this Activity was finished, false otherwise. |
onWindowStartingSupportActionMode
ActionMode onWindowStartingSupportActionMode (ActionMode.Callback callback)
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 |
Returns | |
---|---|
ActionMode |
The ActionMode that was started, or null if the system should present it |
openOptionsMenu
void openOptionsMenu ()
setContentView
void setContentView (int layoutResID)
Parameters | |
---|---|
layoutResID |
int |
setContentView
void setContentView (View view, ViewGroup.LayoutParams params)
Parameters | |
---|---|
view |
View |
params |
ViewGroup.LayoutParams |
setSupportActionBar
void setSupportActionBar (Toolbar toolbar)
Set a Toolbar
to act as the
ActionBar
for this Activity window.
When set to a non-null value the getActionBar()
method will return
an 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
|
setSupportProgress
void setSupportProgress (int progress)
This method was deprecated
in API level 25.1.0.
Progress bars are no longer provided in AppCompat.
Parameters | |
---|---|
progress |
int |
setSupportProgressBarIndeterminate
void setSupportProgressBarIndeterminate (boolean indeterminate)
This method was deprecated
in API level 25.1.0.
Progress bars are no longer provided in AppCompat.
Parameters | |
---|---|
indeterminate |
boolean |
setSupportProgressBarIndeterminateVisibility
void setSupportProgressBarIndeterminateVisibility (boolean visible)
This method was deprecated
in API level 25.1.0.
Progress bars are no longer provided in AppCompat.
Parameters | |
---|---|
visible |
boolean |
setSupportProgressBarVisibility
void setSupportProgressBarVisibility (boolean visible)
This method was deprecated
in API level 25.1.0.
Progress bars are no longer provided in AppCompat.
Parameters | |
---|---|
visible |
boolean |
setTheme
void setTheme (int resid)
Parameters | |
---|---|
resid |
int |
startSupportActionMode
ActionMode startSupportActionMode (ActionMode.Callback callback)
Start an action mode.
Parameters | |
---|---|
callback |
ActionMode.Callback : Callback that will manage lifecycle events for this context mode |
Returns | |
---|---|
ActionMode |
The ContextMode that was started, or null if it was canceled |
supportInvalidateOptionsMenu
void supportInvalidateOptionsMenu ()
This method is deprecated.
Call invalidateOptionsMenu()
directly.
Support library version of invalidateOptionsMenu()
.
Invalidate the activity's options menu. This will cause relevant presentations of the menu to fully update via calls to onCreateOptionsMenu and onPrepareOptionsMenu the next time the menu is requested.
supportNavigateUpTo
void supportNavigateUpTo (Intent upIntent)
Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity
in the process. upIntent will have the flag 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
|
supportRequestWindowFeature
boolean supportRequestWindowFeature (int featureId)
Enable extended support library window features.
This is a convenience for calling
getWindow().requestFeature()
.
Parameters | |
---|---|
featureId |
int : The desired feature as defined in
Window or WindowCompat . |
Returns | |
---|---|
boolean |
Returns true if the requested feature is supported and now enabled. |
supportShouldUpRecreateTask
boolean supportShouldUpRecreateTask (Intent targetIntent)
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 TaskStackBuilder
or another similar mechanism to perform up navigation.
Parameters | |
---|---|
targetIntent |
Intent : An intent representing the target destination for up navigation |
Returns | |
---|---|
boolean |
true if navigating up should recreate a new task stack, false if the same task should be used for the destination |
Protected methods
onCreate
void onCreate (Bundle savedInstanceState)
Perform initialization of all fragments.
Parameters | |
---|---|
savedInstanceState |
Bundle |
onDestroy
void onDestroy ()
Destroy all fragments.
onPostResume
void onPostResume ()
Dispatch onResume() to fragments.
onSaveInstanceState
void onSaveInstanceState (Bundle outState)
Save all appropriate fragment state.
Parameters | |
---|---|
outState |
Bundle |
onStart
void onStart ()
Dispatch onStart() to all fragments.
onStop
void onStop ()
Dispatch onStop() to all fragments.
onTitleChanged
void onTitleChanged (CharSequence title, int color)
Parameters | |
---|---|
title |
CharSequence |
color |
int |
Interfaces
Classes
- ActionBar
- ActionBar.LayoutParams
- ActionBar.Tab
- ActionBarDrawerToggle
- AlertDialog
- AlertDialog.Builder
- AppCompatActivity
- AppCompatDelegate
- AppCompatDialog
- AppCompatDialogFragment
- AppCompatViewInflater
- MediaRouteActionProvider
- MediaRouteButton
- MediaRouteChooserDialog
- MediaRouteChooserDialogFragment
- MediaRouteControllerDialog
- MediaRouteControllerDialogFragment
- MediaRouteDialogFactory
- MediaRouteDiscoveryFragment