AppCompatActivity
public class AppCompatActivity extends FragmentActivity implements AppCompatCallback, TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider
Base class for activities that wish to use some of the newer platform features on older Android devices. Some of these backported features include:
- Using the action bar, including action items, navigation modes and more with the
setSupportActionBarAPI. - Built-in switching between light and dark themes by using the
Theme.AppCompat.DayNighttheme andsetDefaultNightModeAPI. - Integration with
DrawerLayoutby using thegetDrawerToggleDelegateAPI.
Note that every activity that extends this class has to be themed with Theme.AppCompat or a theme that extends that theme.
Summary
Public constructors |
|---|
|
Default constructor for AppCompatActivity. |
@ContentViewAlternate constructor that can be used to provide a default layout that will be inflated as part of |
Public methods |
|
|---|---|
void |
addContentView(View view, ViewGroup.LayoutParams params) |
void |
|
boolean |
dispatchKeyEvent(KeyEvent event) |
T |
<T extends View> findViewById(@IdRes int id) |
@NonNull AppCompatDelegate |
|
@Nullable ActionBarDrawerToggle.Delegate |
|
@NonNull MenuInflater |
|
Resources |
|
@Nullable ActionBar |
Support library version of |
@Nullable Intent |
Obtain an |
void |
|
void |
onConfigurationChanged(@NonNull Configuration newConfig){@inheritDoc} |
void |
|
void |
Support version of |
boolean |
|
final boolean |
onMenuItemSelected(int featureId, @NonNull MenuItem item) |
boolean |
onMenuOpened(int featureId, Menu menu)Please note: AppCompat uses its own feature id for the action bar: |
void |
onPanelClosed(int featureId, @NonNull Menu menu)Please note: AppCompat uses its own feature id for the action bar: |
void |
Support version of |
void |
Notifies the activity that a support action mode has finished. |
void |
Notifies the Activity that a support action mode has been started. |
void |
This method is deprecated. Use onContentChanged instead. |
boolean |
This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar. |
@Nullable ActionMode |
Called when a support action mode is being started for this window. |
void |
|
void |
setContentView(@LayoutRes int layoutResID) |
void |
setContentView(View view) |
void |
setContentView(View view, ViewGroup.LayoutParams params) |
void |
setSupportActionBar(@Nullable Toolbar toolbar)Set a |
void |
This method is deprecated. Progress bars are no longer provided in AppCompat. |
void |
This method is deprecated. Progress bars are no longer provided in AppCompat. |
void |
This method is deprecated. Progress bars are no longer provided in AppCompat. |
void |
This method is deprecated. Progress bars are no longer provided in AppCompat. |
void |
|
@Nullable ActionMode |
startSupportActionMode(@NonNull ActionMode.Callback callback)Start an action mode. |
void |
This method is deprecated. Call |
void |
supportNavigateUpTo(@NonNull Intent upIntent)Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag |
boolean |
supportRequestWindowFeature(int featureId)Enable extended support library window features. |
boolean |
supportShouldUpRecreateTask(@NonNull Intent targetIntent)Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent. |
Protected methods |
|
|---|---|
void |
attachBaseContext(Context newBase) |
void |
Destroy all fragments. |
void |
onLocalesChanged(@NonNull LocaleListCompat locales)Called when the locales have been changed. |
void |
onNightModeChanged(int mode)Called when the night mode has changed. |
void |
onPostCreate(@Nullable Bundle savedInstanceState) |
void |
Dispatch onResume() to fragments. |
void |
onStart()Dispatch onStart() to all fragments. |
void |
onStop()Dispatch onStop() to all fragments. |
void |
onTitleChanged(CharSequence title, int color) |
Extension functions |
|
|---|---|
final void |
ActivityKt.setupActionBarWithNavController(Sets up the ActionBar returned by |
final void |
ActivityKt.setupActionBarWithNavController(Sets up the ActionBar returned by |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited fields |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
AppCompatActivity
public AppCompatActivity()
Default constructor for AppCompatActivity. All Activities must have a default constructor for API 27 and lower devices or when using the default android.app.AppComponentFactory.
AppCompatActivity
@ContentView
public AppCompatActivity(@LayoutRes int contentLayoutId)
Alternate constructor that can be used to provide a default layout that will be inflated as part of super.onCreate(savedInstanceState).
This should generally be called from your constructor that takes no parameters, as is required for API 27 and lower or when using the default android.app.AppComponentFactory.
| See also | |
|---|---|
AppCompatActivity |
Public methods
getDelegate
public @NonNull AppCompatDelegate getDelegate()
| Returns | |
|---|---|
@NonNull AppCompatDelegate |
The |
getDrawerToggleDelegate
public @Nullable ActionBarDrawerToggle.Delegate getDrawerToggleDelegate()
| Returns | |
|---|---|
@Nullable ActionBarDrawerToggle.Delegate |
Delegate to use for ActionBarDrawableToggles, or null if the Activity does not wish to override the default behavior. |
getSupportActionBar
public @Nullable ActionBar getSupportActionBar()
Support library version of getActionBar.
Retrieve a reference to this activity's ActionBar.
getSupportParentActivityIntent
public @Nullable Intent getSupportParentActivityIntent()
Obtain an android.content.Intent that will launch an explicit target activity specified by sourceActivity's PARENT_ACTIVITY
onConfigurationChanged
public void onConfigurationChanged(@NonNull Configuration newConfig)
{@inheritDoc}
Dispatches this call to all listeners added via addOnConfigurationChangedListener.
onCreateSupportNavigateUpTaskStack
public void onCreateSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder)
Support version of onCreateNavigateUpTaskStack. 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 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.
| Parameters | |
|---|---|
@NonNull TaskStackBuilder builder |
An empty TaskStackBuilder - the application should add intents representing the desired task stack |
onMenuItemSelected
public final boolean onMenuItemSelected(int featureId, @NonNull MenuItem item)
onMenuOpened
public boolean onMenuOpened(int featureId, Menu menu)
Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.
onPanelClosed
public void onPanelClosed(int featureId, @NonNull Menu menu)
Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.
onPrepareSupportNavigateUpTaskStack
public void onPrepareSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder)
Support version of onPrepareNavigateUpTaskStack. 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. 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 | |
|---|---|
@NonNull TaskStackBuilder builder |
A TaskStackBuilder that has been populated with Intents by onCreateNavigateUpTaskStack. |
onSupportActionModeFinished
@CallSuper
public void onSupportActionModeFinished(@NonNull ActionMode mode)
Notifies the activity that a support action mode has finished. Activity subclasses overriding this method should call the superclass implementation.
| Parameters | |
|---|---|
@NonNull ActionMode mode |
The action mode that just finished. |
onSupportActionModeStarted
@CallSuper
public void onSupportActionModeStarted(@NonNull ActionMode mode)
Notifies the Activity that a support action mode has been started. Activity subclasses overriding this method should call the superclass implementation.
| Parameters | |
|---|---|
@NonNull ActionMode mode |
The new action mode. |
onSupportNavigateUp
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 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, and supportNavigateUpTo for help implementing custom Up navigation.
| Returns | |
|---|---|
boolean |
true if Up navigation completed successfully and this Activity was finished, false otherwise. |
onWindowStartingSupportActionMode
public @Nullable ActionMode onWindowStartingSupportActionMode(@NonNull 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 | |
|---|---|
@NonNull ActionMode.Callback callback |
Callback to control the lifecycle of this action mode |
| Returns | |
|---|---|
@Nullable ActionMode |
The ActionMode that was started, or null if the system should present it |
setSupportActionBar
public void setSupportActionBar(@Nullable Toolbar toolbar)
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.
startSupportActionMode
public @Nullable ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback)
Start an action mode.
| Parameters | |
|---|---|
@NonNull ActionMode.Callback callback |
Callback that will manage lifecycle events for this context mode |
| Returns | |
|---|---|
@Nullable ActionMode |
The ContextMode that was started, or null if it was canceled |
supportInvalidateOptionsMenu
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.
supportNavigateUpTo
public void supportNavigateUpTo(@NonNull 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.
supportRequestWindowFeature
public boolean supportRequestWindowFeature(int featureId)
Enable extended support library window features.
This is a convenience for calling getWindow().requestFeature().
| Parameters | |
|---|---|
int featureId |
The desired feature as defined in |
| Returns | |
|---|---|
boolean |
Returns true if the requested feature is supported and now enabled. |
| See also | |
|---|---|
requestWindowFeature |
|
requestFeature |
supportShouldUpRecreateTask
public boolean supportShouldUpRecreateTask(@NonNull 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 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 | |
|---|---|
@NonNull Intent targetIntent |
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
onLocalesChanged
protected void onLocalesChanged(@NonNull LocaleListCompat locales)
Called when the locales have been changed. See applyAppLocales for more information.
| Parameters | |
|---|---|
@NonNull LocaleListCompat locales |
the localeListCompat which has been applied |
onNightModeChanged
protected void onNightModeChanged(int mode)
Called when the night mode has changed. See applyDayNight for more information.
| Parameters | |
|---|---|
int mode |
the night mode which has been applied |
Extension functions
ActivityKt.setupActionBarWithNavController
public final void ActivityKt.setupActionBarWithNavController(
@NonNull AppCompatActivity receiver,
@NonNull NavController navController,
@NonNull AppBarConfiguration configuration
)
Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.
By calling this method, the title in the action bar will automatically be updated when the destination changes (assuming there is a valid label).
The AppBarConfiguration you provide controls how the Navigation button is displayed.
You are responsible for calling NavController.navigateUp to handle the Navigation button. Typically this is done in AppCompatActivity.onSupportNavigateUp.
| Parameters | |
|---|---|
@NonNull NavController navController |
The NavController whose navigation actions will be reflected in the title of the action bar. |
@NonNull AppBarConfiguration configuration |
Additional configuration options for customizing the behavior of the ActionBar |
ActivityKt.setupActionBarWithNavController
public final void ActivityKt.setupActionBarWithNavController(
@NonNull AppCompatActivity receiver,
@NonNull NavController navController,
DrawerLayout drawerLayout
)
Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.
By calling this method, the title in the action bar will automatically be updated when the destination changes (assuming there is a valid label).
The start destination of your navigation graph is considered the only top level destination. On the start destination of your navigation graph, the ActionBar will show the drawer icon if the given drawerLayout is non null. On all other destinations, the ActionBar will show the Up button.
You are responsible for calling NavController.navigateUp to handle the Navigation button. Typically this is done in AppCompatActivity.onSupportNavigateUp.
| Parameters | |
|---|---|
@NonNull NavController navController |
The NavController whose navigation actions will be reflected in the title of the action bar. |
DrawerLayout drawerLayout |
The DrawerLayout that should be toggled from the Navigation button |