1. 程式人生 > >android官方API之AppCompatActivity

android官方API之AppCompatActivity

來源:https://developer.android.com/reference/android/support/v7/app/AppCompatActivity

AppCompatActivity

public class AppCompatActivity 
extends FragmentActivity implements AppCompatCallbackTaskStackBuilder.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
int DEFAULT_KEYS_DIALER

 

int DEFAULT_KEYS_DISABLE

 

int DEFAULT_KEYS_SEARCH_GLOBAL

 

int DEFAULT_KEYS_SEARCH_LOCAL

 

int DEFAULT_KEYS_SHORTCUT

 

int RESULT_CANCELED

 

int RESULT_FIRST_USER

 

int RESULT_OK

 

From class android.content.Context
String ACCESSIBILITY_SERVICE

 

String ACCOUNT_SERVICE

 

String ACTIVITY_SERVICE

 

String ALARM_SERVICE

 

String APPWIDGET_SERVICE

 

String APP_OPS_SERVICE

 

String AUDIO_SERVICE

 

String BATTERY_SERVICE

 

int BIND_ABOVE_CLIENT

 

int BIND_ADJUST_WITH_ACTIVITY

 

int BIND_ALLOW_OOM_MANAGEMENT

 

int BIND_AUTO_CREATE

 

int BIND_DEBUG_UNBIND

 

int BIND_EXTERNAL_SERVICE

 

int BIND_IMPORTANT

 

int BIND_NOT_FOREGROUND

 

int BIND_WAIVE_PRIORITY

 

String BLUETOOTH_SERVICE

 

String CAMERA_SERVICE

 

String CAPTIONING_SERVICE

 

String CARRIER_CONFIG_SERVICE

 

String CLIPBOARD_SERVICE

 

String COMPANION_DEVICE_SERVICE

 

String CONNECTIVITY_SERVICE

 

String CONSUMER_IR_SERVICE

 

int CONTEXT_IGNORE_SECURITY

 

int CONTEXT_INCLUDE_CODE

 

int CONTEXT_RESTRICTED

 

String CROSS_PROFILE_APPS_SERVICE

 

String DEVICE_POLICY_SERVICE

 

String DISPLAY_SERVICE

 

String DOWNLOAD_SERVICE

 

String DROPBOX_SERVICE

 

String FINGERPRINT_SERVICE

 

String HARDWARE_PROPERTIES_SERVICE

 

String INPUT_METHOD_SERVICE

 

String INPUT_SERVICE

 

String IPSEC_SERVICE

 

String JOB_SCHEDULER_SERVICE

 

String KEYGUARD_SERVICE

 

String LAUNCHER_APPS_SERVICE

 

String LAYOUT_INFLATER_SERVICE

 

String LOCATION_SERVICE

 

String MEDIA_PROJECTION_SERVICE

 

String MEDIA_ROUTER_SERVICE

 

String MEDIA_SESSION_SERVICE

 

String MIDI_SERVICE

 

int MODE_APPEND

 

int MODE_ENABLE_WRITE_AHEAD_LOGGING

 

int MODE_MULTI_PROCESS

 

int MODE_NO_LOCALIZED_COLLATORS

 

int MODE_PRIVATE

 

int MODE_WORLD_READABLE

 

int MODE_WORLD_WRITEABLE

 

String NETWORK_STATS_SERVICE

 

String NFC_SERVICE

 

String NOTIFICATION_SERVICE

 

String NSD_SERVICE

 

String POWER_SERVICE

 

String PRINT_SERVICE

 

int RECEIVER_VISIBLE_TO_INSTANT_APPS

 

String RESTRICTIONS_SERVICE

 

String SEARCH_SERVICE

 

String SENSOR_SERVICE

 

String SHORTCUT_SERVICE

 

String STORAGE_SERVICE

 

String STORAGE_STATS_SERVICE

 

String SYSTEM_HEALTH_SERVICE

 

String TELECOM_SERVICE

 

String TELEPHONY_SERVICE

 

String TELEPHONY_SUBSCRIPTION_SERVICE

 

String TEXT_CLASSIFICATION_SERVICE

 

String TEXT_SERVICES_MANAGER_SERVICE

 

String TV_INPUT_SERVICE

 

String UI_MODE_SERVICE

 

String USAGE_STATS_SERVICE

 

String USB_SERVICE

 

String USER_SERVICE

 

String VIBRATOR_SERVICE

 

String WALLPAPER_SERVICE

 

String WIFI_AWARE_SERVICE

 

String WIFI_P2P_SERVICE

 

String WIFI_RTT_RANGING_SERVICE

 

String WIFI_SERVICE

 

String WINDOW_SERVICE

 

From interface android.content.ComponentCallbacks2
int TRIM_MEMORY_BACKGROUND

 

int TRIM_MEMORY_COMPLETE

 

int TRIM_MEMORY_MODERATE

 

int TRIM_MEMORY_RUNNING_CRITICAL

 

int TRIM_MEMORY_RUNNING_LOW

 

int TRIM_MEMORY_RUNNING_MODERATE

 

int TRIM_MEMORY_UI_HIDDEN

 

Inherited fields

From class android.app.Activity
protected static final int[] FOCUSED_STATE_SET

 

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 getActionBar().

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 invalidateOptionsMenu()
void onConfigurationChanged(Configuration newConfig)

Dispatch configuration change to all fragments.

void onContentChanged()
void onCreateSupportNavigateUpTaskStack(TaskStackBuilder builder)

Support version of onCreateNavigateUpTaskStack(android.app.TaskStackBuilder).

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:FEATURE_SUPPORT_ACTION_BAR.

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.

void onPrepareSupportNavigateUpTaskStack(TaskStackBuilder builder)

Support version of onPrepareNavigateUpTaskStack(android.app.TaskStackBuilder).

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 onContentChanged() instead.

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 Toolbar to act as the ActionBar for this Activity window.

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 invalidateOptionsMenu() directly.

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)

Inherited methods

From class android.support.v4.app.FragmentActivity
void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

Print the Activity's state into the given stream.

Object getLastCustomNonConfigurationInstance()

Return the value previously returned from onRetainCustomNonConfigurationInstance().

Lifecycle getLifecycle()

Returns the Lifecycle of the provider.

FragmentManager getSupportFragmentManager()

Return the FragmentManager for interacting with fragments associated with this activity.

LoaderManager getSupportLoaderManager()
ViewModelStore getViewModelStore()

Returns the ViewModelStore associated with this activity

void onActivityResult(int requestCode, int resultCode, Intent data)

Dispatch incoming result to the correct fragment.

void onAttachFragment(Fragment fragment)

Called when a fragment is attached to the activity.

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.

void onCreate(Bundle savedInstanceState)

Perform initialization of all fragments.

boolean onCreatePanelMenu(int featureId, Menu menu)

Dispatch to Fragment.onCreateOptionsMenu().

View onCreateView(View parent, String name, Context context, AttributeSetattrs)
View onCreateView(String name, Context context, AttributeSet attrs)
void onDestroy()

Destroy all fragments.

void onLowMemory()

Dispatch onLowMemory() to all fragments.

boolean onMenuItemSelected(int featureId, MenuItem item)

Dispatch context and options menu to fragments.

void onMultiWindowModeChanged(boolean isInMultiWindowMode)

 

Note: If you override this method you must call super.onMultiWindowModeChanged to correctly dispatch the event to support fragments attached to this activity.

void onNewIntent(Intent intent)

Handle onNewIntent() to inform the fragment manager that the state is not saved.

void onPanelClosed(int featureId, Menu menu)

Call onOptionsMenuClosed() on fragments.

void onPause()

Dispatch onPause() to fragments.

void onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

 

Note: If you override this method you must call super.onPictureInPictureModeChangedto correctly dispatch the event to support fragments attached to this activity.

void onPostResume()

Dispatch onResume() to fragments.

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

Dispatch onPrepareOptionsMenu() to fragments.

void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)

Callback for the result from requesting permissions.

void onResume()

Dispatch onResume() to fragments.

void onResumeFragments()

This is the fragment-orientated version of onResume() that you can override to perform operations in the Activity at the same point where its fragments are resumed.

Object onRetainCustomNonConfigurationInstance()

Use this instead of onRetainNonConfigurationInstance().

final Object onRetainNonConfigurationInstance()

Retain all appropriate fragment state.

void onSaveInstanceState(Bundle outState)

Save all appropriate fragment state.

void onStart()

Dispatch onStart() to all fragments.

void onStateNotSaved()

Hook in to note that fragment state is no longer saved.

void onStop()

Dispatch onStop() to all fragments.

void setEnterSharedElementCallback(SharedElementCallback callback)

When makeSceneTransitionAnimation(Activity, android.view.View, String)was used to start an Activity, callback will be called to handle shared elements on the launchedActivity.

void setExitSharedElementCallback(SharedElementCallback listener)

When makeSceneTransitionAnimation(Activity, android.view.View, String)was used to start an Activity, listener will be called to handle shared elements on the launchingActivity.

void startActivityForResult(Intent intent, int requestCode, Bundle options)
void startActivityForResult(Intent intent, int requestCode)

Modifies the standard behavior to allow results to be delivered to fragments.

void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode)

Called by Fragment.startActivityForResult() to implement its behavior.

void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode, Bundle options)

Called by Fragment.startActivityForResult() to implement its behavior.

void startIntentSenderForResult(IntentSender intent, int requestCode, IntentfillInIntent, int flagsMask, int flagsValues, int extraFlags)
void startIntentSenderForResult(IntentSender intent, int requestCode, IntentfillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundleoptions)
void startIntentSenderFromFragment(Fragment fragment, IntentSender intent,int requestCode, Intent fillInIntent, int flagsMask, int flagsValues,int extraFlags, Bundle options)

Called by Fragment.startIntentSenderForResult() to implement its behavior.

void supportFinishAfterTransition()

Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition.

void supportInvalidateOptionsMenu()

This method was deprecated in API level 26.1.0. Call invalidateOptionsMenu() directly.

void supportPostponeEnterTransition()

Support library version of postponeEnterTransition() that works only on API 21 and later.

void supportStartPostponedEnterTransition()

Support library version of startPostponedEnterTransition() that only works with API 21 and later.

final void validateRequestPermissionsRequestCode(int requestCode)
From class android.app.Activity
void addContentView(View arg0, ViewGroup.LayoutParams arg1)
void attachBaseContext(Context arg0)
void closeContextMenu()
void closeOptionsMenu()
PendingIntent createPendingResult(int arg0, Intent arg1, int arg2)
final void dismissDialog(int arg0)
final void