Android APIs
public abstract class

AppCompatDelegate

extends Object
java.lang.Object
   ↳ android.support.v7.app.AppCompatDelegate

Class Overview

This class represents a delegate which you can use to extend AppCompat's support to any Activity.

When using an AppCompatDelegate, you should any methods exposed in it rather than the Activity method of the same name. This applies to:

There also some Activity lifecycle methods which should be proxied to the delegate:

An Activity can only be linked with one AppCompatDelegate instance, so the instance returned from create(Activity, AppCompatCallback) should be kept until the Activity is destroyed.

Summary

Constants
int FEATURE_ACTION_MODE_OVERLAY Flag for specifying the behavior of action modes when an Action Bar is not present.
int FEATURE_SUPPORT_ACTION_BAR Flag for enabling the support Action Bar.
int FEATURE_SUPPORT_ACTION_BAR_OVERLAY Flag for requesting an support Action Bar that overlays window content.
Public Methods
abstract void addContentView(View v, ViewGroup.LayoutParams lp)
static AppCompatDelegate create(Activity activity, AppCompatCallback callback)
Create a AppCompatDelegate to use with activity.
static AppCompatDelegate create(Dialog dialog, AppCompatCallback callback)
Create a AppCompatDelegate to use with dialog.
abstract View createView(View parent, String name, Context context, AttributeSet attrs)
This should be called from a LayoutInflaterFactory in order to return tint-aware widgets.
abstract ActionBarDrawerToggle.Delegate getDrawerToggleDelegate()
Returns an ActionBarDrawerToggle.Delegate which can be returned from your Activity if it implements ActionBarDrawerToggle.DelegateProvider.
abstract MenuInflater getMenuInflater()
Return the value of this call from your getMenuInflater()
abstract ActionBar getSupportActionBar()
Support library version of getActionBar().
abstract boolean hasWindowFeature(int featureId)
Query for the availability of a certain feature.
abstract void installViewFactory()
Installs AppCompat's LayoutInflater Factory so that it can replace the framework widgets with compatible tinted versions.
abstract void invalidateOptionsMenu()
abstract boolean isHandleNativeActionModesEnabled()
Returns whether AppCompat handles any native action modes itself.
abstract void onConfigurationChanged(Configuration newConfig)
abstract void onCreate(Bundle savedInstanceState)
Should be called from Activity.onCreate()
abstract void onDestroy()
Should be called from onDestroy()
abstract void onPostCreate(Bundle savedInstanceState)
Should be called from onPostCreate(android.os.Bundle)
abstract void onPostResume()
Should be called from onPostResume()
abstract void onStop()
Should be called from Activity.onStop()
abstract boolean requestWindowFeature(int featureId)
Enable extended window features.
abstract void setContentView(int resId)
Should be called instead of setContentView(int)}
abstract void setContentView(View v)
Should be called instead of setContentView(android.view.View)}
abstract void setContentView(View v, ViewGroup.LayoutParams lp)
abstract void setHandleNativeActionModesEnabled(boolean enabled)
Whether AppCompat handles any native action modes itself.
abstract void setSupportActionBar(Toolbar toolbar)
Set a Toolbar to act as the ActionBar for this delegate.
abstract void setTitle(CharSequence title)
Should be called from onTitleChanged(CharSequence, int)}
abstract ActionMode startSupportActionMode(ActionMode.Callback callback)
Start an action mode.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int FEATURE_ACTION_MODE_OVERLAY

Flag for specifying the behavior of action modes when an Action Bar is not present. If overlay is enabled, the action mode UI will be allowed to cover existing window content.

Constant Value: 10 (0x0000000a)

public static final int FEATURE_SUPPORT_ACTION_BAR

Flag for enabling the support Action Bar.

This is enabled by default for some devices. The Action Bar replaces the title bar and provides an alternate location for an on-screen menu button on some devices.

Constant Value: 108 (0x0000006c)

public static final int FEATURE_SUPPORT_ACTION_BAR_OVERLAY

Flag for requesting an support Action Bar that overlays window content. Normally an Action Bar will sit in the space above window content, but if this feature is requested along with FEATURE_SUPPORT_ACTION_BAR it will be layered over the window content itself. This is useful if you would like your app to have more control over how the Action Bar is displayed, such as letting application content scroll beneath an Action Bar with a transparent background or otherwise displaying a transparent/translucent Action Bar over application content.

This mode is especially useful with View.SYSTEM_UI_FLAG_FULLSCREEN, which allows you to seamlessly hide the action bar in conjunction with other screen decorations. When an ActionBar is in this mode it will adjust the insets provided to View.fitSystemWindows(Rect) to include the content covered by the action bar, so you can do layout within that space.

Constant Value: 109 (0x0000006d)

Public Methods

public abstract void addContentView (View v, ViewGroup.LayoutParams lp)

public static AppCompatDelegate create (Activity activity, AppCompatCallback callback)

Create a AppCompatDelegate to use with activity.

Parameters
callback An optional callback for AppCompat specific events

public static AppCompatDelegate create (Dialog dialog, AppCompatCallback callback)

Create a AppCompatDelegate to use with dialog.

Parameters
callback An optional callback for AppCompat specific events

public abstract View createView (View parent, String name, Context context, AttributeSet attrs)

This should be called from a LayoutInflaterFactory in order to return tint-aware widgets.

This is only needed if you are using your own LayoutInflater factory, and have therefore not installed the default factory via installViewFactory().

public abstract ActionBarDrawerToggle.Delegate getDrawerToggleDelegate ()

Returns an ActionBarDrawerToggle.Delegate which can be returned from your Activity if it implements ActionBarDrawerToggle.DelegateProvider.

public abstract MenuInflater getMenuInflater ()

Return the value of this call from your getMenuInflater()

public abstract ActionBar getSupportActionBar ()

Support library version of getActionBar().

Returns
  • AppCompat's action bar, or null if it does not have one.

public abstract boolean hasWindowFeature (int featureId)

Query for the availability of a certain feature.

This should be called instead of hasFeature(int).

Parameters
featureId The feature ID to check
Returns
  • true if the feature is enabled, false otherwise.

public abstract void installViewFactory ()

Installs AppCompat's LayoutInflater Factory so that it can replace the framework widgets with compatible tinted versions. This should be called before super.onCreate() as so:

 protected void onCreate(Bundle savedInstanceState) {
     getDelegate().installViewFactory();
     super.onCreate(savedInstanceState);
     getDelegate().onCreate(savedInstanceState);

     // ...
 }
 
If you are using your own Factory or Factory2 then you can omit this call, and instead call createView(android.view.View, String, android.content.Context, android.util.AttributeSet) from your factory to return any compatible widgets.

public abstract void invalidateOptionsMenu ()

public abstract boolean isHandleNativeActionModesEnabled ()

Returns whether AppCompat handles any native action modes itself.

Returns
  • true if AppCompat should handle native action modes.

public abstract void onConfigurationChanged (Configuration newConfig)

public abstract void onCreate (Bundle savedInstanceState)

Should be called from Activity.onCreate()

public abstract void onDestroy ()

Should be called from onDestroy()

public abstract void onPostCreate (Bundle savedInstanceState)

Should be called from onPostCreate(android.os.Bundle)

public abstract void onPostResume ()

Should be called from onPostResume()

public abstract void onStop ()

Should be called from Activity.onStop()

public abstract boolean requestWindowFeature (int featureId)

Enable extended window features. This should be called instead of requestWindowFeature(int) or getWindow().requestFeature().

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

public abstract void setContentView (int resId)

Should be called instead of setContentView(int)}

public abstract void setContentView (View v)

Should be called instead of setContentView(android.view.View)}

public abstract void setContentView (View v, ViewGroup.LayoutParams lp)

public abstract void setHandleNativeActionModesEnabled (boolean enabled)

Whether AppCompat handles any native action modes itself.

This methods only takes effect on ICE_CREAM_SANDWICH and above.

Parameters
enabled whether AppCompat should handle native action modes.

public abstract void setSupportActionBar (Toolbar toolbar)

Set a Toolbar to act as the ActionBar for this delegate.

When set to a non-null value the getSupportActionBar() ()} 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 to set as the Activity's action bar

public abstract void setTitle (CharSequence title)

Should be called from onTitleChanged(CharSequence, int)}

public abstract ActionMode startSupportActionMode (ActionMode.Callback callback)

Start an action mode.

Parameters
callback Callback that will manage lifecycle events for this context mode
Returns
  • The ContextMode that was started, or null if it was canceled