to top
Android APIs
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ android.support.v4.app.FragmentActivity
             ↳ android.support.v7.app.ActionBarActivity

Class Overview

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

[Expand]
Inherited Constants
From class android.app.Activity
From class android.content.Context
From interface android.content.ComponentCallbacks2
[Expand]
Inherited Fields
From class android.app.Activity
Public Constructors
ActionBarActivity()
Public Methods
void addContentView(View view, ViewGroup.LayoutParams params)
Add an additional content view to the activity.
final ActionBarDrawerToggle.Delegate getDrawerToggleDelegate()
MenuInflater getMenuInflater()
Returns a MenuInflater with this context.
ActionBar getSupportActionBar()
Support library version of getActionBar().
abstract FragmentManager getSupportFragmentManager()
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.
void onBackPressed()
Take care of popping the fragment back stack or finishing the activity as appropriate.
void onConfigurationChanged(Configuration newConfig)
Dispatch configuration change to all fragments.
final void onContentChanged()
boolean onCreatePanelMenu(int featureId, Menu menu)
Dispatch to Fragment.onCreateOptionsMenu().
View onCreatePanelView(int featureId)
Default implementation of onCreatePanelView(int) for activities.
void onCreateSupportNavigateUpTaskStack(TaskStackBuilder builder)
final boolean onMenuItemSelected(int featureId, MenuItem item)
Dispatch context and options menu to fragments.
boolean onPreparePanel(int featureId, View view, Menu menu)
Dispatch onPrepareOptionsMenu() to fragments.
void onPrepareSupportNavigateUpTaskStack(TaskStackBuilder builder)
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 hook is called whenever the content view of the screen changes.
boolean onSupportNavigateUp()
This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar.
void setContentView(View view)
Set the activity content to an explicit view.
void setContentView(int layoutResID)
Set the activity content from a layout resource.
void setContentView(View view, ViewGroup.LayoutParams params)
Set the activity content to an explicit view.
void setSupportProgress(int progress)
Support library version of setProgress(int).
void setSupportProgressBarIndeterminate(boolean indeterminate)
Support library version of setProgressBarIndeterminate(boolean)

Sets whether the horizontal progress bar in the title should be indeterminate (the circular is always indeterminate).

void setSupportProgressBarIndeterminateVisibility(boolean visible)
Support library version of setProgressBarIndeterminateVisibility(boolean)

Sets the visibility of the indeterminate progress bar in the title.

void setSupportProgressBarVisibility(boolean visible)
Support library version of setProgressBarVisibility(boolean)

Sets the visibility of the progress bar in the title.

ActionMode startSupportActionMode(ActionMode.Callback callback)
void supportInvalidateOptionsMenu()
Support library version of invalidateOptionsMenu().
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 and loaders.
void onPostResume()
Dispatch onResume() to fragments.
void onStop()
Dispatch onStop() to all fragments.
void onTitleChanged(CharSequence title, int color)
[Expand]
Inherited Methods
From class android.support.v4.app.FragmentActivity
From class android.app.Activity
From class android.view.ContextThemeWrapper
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2
From interface android.support.v4.app.ActionBarDrawerToggle.DelegateProvider
From interface android.support.v4.app.TaskStackBuilder.SupportParentable
From interface android.view.KeyEvent.Callback
From interface android.view.LayoutInflater.Factory
From interface android.view.LayoutInflater.Factory2
From interface android.view.View.OnCreateContextMenuListener
From interface android.view.Window.Callback

Public Constructors

public ActionBarActivity ()

Public Methods

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

Add an additional content view to the activity. Added after any existing ones in the activity -- existing views are NOT removed.

Parameters
view The desired content to display.
params Layout parameters for the view.

public final ActionBarDrawerToggle.Delegate getDrawerToggleDelegate ()

public MenuInflater getMenuInflater ()

Returns a MenuInflater with this context.

public ActionBar getSupportActionBar ()

Support library version of getActionBar().

Retrieve a reference to this activity's ActionBar.

Returns
  • The Activity's ActionBar, or null if it does not have one.

public abstract FragmentManager getSupportFragmentManager ()

public 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
  • a new Intent targeting the defined parent activity of sourceActivity

public void onBackPressed ()

Take care of popping the fragment back stack or finishing the activity as appropriate.

public void onConfigurationChanged (Configuration newConfig)

Dispatch configuration change to all fragments.

Parameters
newConfig The new device configuration.

public final void onContentChanged ()

public boolean onCreatePanelMenu (int featureId, Menu menu)

Dispatch to Fragment.onCreateOptionsMenu().

Parameters
featureId The panel being created.
menu The menu inside the panel.
Returns
  • boolean You must return true for the panel to be displayed; if you return false it will not be shown.

public View onCreatePanelView (int featureId)

Default implementation of onCreatePanelView(int) for activities. This simply returns null so that all panel sub-windows will have the default menu behavior.

Parameters
featureId Which panel is being created.
Returns
  • view The top-level view to place in the panel.

public 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(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(TaskStackBuilder).

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

public final boolean onMenuItemSelected (int featureId, MenuItem item)

Dispatch context and options menu to fragments.

Parameters
featureId The panel that the menu is in.
item The menu item that was selected.
Returns
  • boolean Return true to finish processing of selection, or false to perform the normal menu handling (calling its Runnable or sending a Message to its target Handler).

public boolean onPreparePanel (int featureId, View view, Menu menu)

Dispatch onPrepareOptionsMenu() to fragments.

Parameters
featureId The panel that is being displayed.
view The View that was returned by onCreatePanelView().
menu If onCreatePanelView() returned null, this is the Menu being displayed in the panel.
Returns
  • boolean You must return true for the panel to be displayed; if you return false it will not be shown.

public 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(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 A TaskStackBuilder that has been populated with Intents by onCreateNavigateUpTaskStack.

public 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 The action mode that just finished.

public 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 The new action mode.

public void onSupportContentChanged ()

This hook is called whenever the content view of the screen changes.

public 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(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(Intent), and supportNavigateUpTo(Intent) for help implementing custom Up navigation.

Returns
  • true if Up navigation completed successfully and this Activity was finished, false otherwise.

public void setContentView (View view)

Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy. It can itself be a complex view hierarchy. When calling this method, the layout parameters of the specified view are ignored. Both the width and the height of the view are set by default to MATCH_PARENT. To use your own layout parameters, invoke setContentView(android.view.View, android.view.ViewGroup.LayoutParams) instead.

Parameters
view The desired content to display.

public void setContentView (int layoutResID)

Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.

Parameters
layoutResID Resource ID to be inflated.

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

Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy. It can itself be a complex view hierarchy.

Parameters
view The desired content to display.
params Layout parameters for the view.

public void setSupportProgress (int progress)

Support library version of setProgress(int).

Sets the progress for the progress bars in the title.

In order for the progress bar to be shown, the feature must be requested via supportRequestWindowFeature(int).

Parameters
progress The progress for the progress bar. Valid ranges are from 0 to 10000 (both inclusive). If 10000 is given, the progress bar will be completely filled and will fade out.

public void setSupportProgressBarIndeterminate (boolean indeterminate)

Support library version of setProgressBarIndeterminate(boolean)

Sets whether the horizontal progress bar in the title should be indeterminate (the circular is always indeterminate).

In order for the progress bar to be shown, the feature must be requested via supportRequestWindowFeature(int).

Parameters
indeterminate Whether the horizontal progress bar should be indeterminate.

public void setSupportProgressBarIndeterminateVisibility (boolean visible)

Support library version of setProgressBarIndeterminateVisibility(boolean)

Sets the visibility of the indeterminate progress bar in the title.

In order for the progress bar to be shown, the feature must be requested via supportRequestWindowFeature(int).

Parameters
visible Whether to show the progress bars in the title.

public void setSupportProgressBarVisibility (boolean visible)

Support library version of setProgressBarVisibility(boolean)

Sets the visibility of the progress bar in the title.

In order for the progress bar to be shown, the feature must be requested via supportRequestWindowFeature(int).

Parameters
visible Whether to show the progress bars in the title.

public ActionMode startSupportActionMode (ActionMode.Callback callback)

public void supportInvalidateOptionsMenu ()

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.

public 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(Intent).

Parameters
upIntent An intent representing the target destination for up navigation

public boolean supportRequestWindowFeature (int featureId)

Enable extended support library window features.

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

Parameters
featureId The desired feature as defined in Window or WindowCompat.
Returns
  • Returns true if the requested feature is supported and now enabled.

public 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(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 An intent representing the target destination for up navigation
Returns
  • true if navigating up should recreate a new task stack, false if the same task should be used for the destination

Protected Methods

protected void onCreate (Bundle savedInstanceState)

Perform initialization of all fragments and loaders.

Parameters
savedInstanceState If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.

protected void onPostResume ()

Dispatch onResume() to fragments.

protected void onStop ()

Dispatch onStop() to all fragments. Ensure all loaders are stopped.

protected void onTitleChanged (CharSequence title, int color)