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

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 void installViewFactory()
Installs AppCompat's LayoutInflater Factory so that it can replace the framework widgets with compatible tinted versions.
abstract void invalidateOptionsMenu()
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 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

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 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 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 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_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