public class AppCompatActivity
extends FragmentActivity implements AppCompatCallback, TaskStackBuilder.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 | ||||||
| |
使用 support library操作栏功能的活动的基类。
您可以添加 ActionBar通过扩展这个类的活动,并设置活动主题对API级别7或更高版本上运行时的活动 Theme.AppCompat或一个相似的主题。
有关如何使用操作栏的信息,请参阅 Action Bar API指南。
Inherited constants |
|---|
android.app.Activity
|
android.content.Context
|
android.content.ComponentCallbacks2
|
Inherited fields |
|---|
android.app.Activity
|
Public constructors |
|
|---|---|
AppCompatActivity() |
|
Protected methods |
|
|---|---|
void |
onCreate(Bundle savedInstanceState) 执行所有片段和加载器的初始化。 |
void |
onDestroy() 销毁所有碎片和装载机。 |
void |
onPostCreate(Bundle savedInstanceState) 当活动启动完成时调用(在 |
void |
onPostResume() 将onResume()分派给片段。 |
void |
onSaveInstanceState(Bundle outState) 保存所有适当的片段状态。 |
void |
onStop() 将onStop()分派给所有片段。 |
void |
onTitleChanged(CharSequence title, int color) |
AppCompatActivity ()
void addContentView (View view, ViewGroup.LayoutParams params)
为活动添加一个额外的内容视图。 在活动中的现有视图之后添加 - 现有视图不会被删除。
| 参数(Parameters) | |
|---|---|
view |
View: The desired content to display. |
params |
ViewGroup.LayoutParams: Layout parameters for the view. |
boolean dispatchKeyEvent (KeyEvent event)
被调用来处理关键事件。 您可以覆盖它以在将所有关键事件分派到窗口之前拦截它们。 确保为应该正常处理的关键事件调用此实现。
| 参数(Parameters) | |
|---|---|
event |
KeyEvent: The key event. |
| 返回(Returns) | |
|---|---|
boolean |
boolean Return true if this event was consumed. |
View findViewById (int id)
查找由 onCreate(Bundle)中处理的XML中的id属性标识的视图。
| 参数(Parameters) | |
|---|---|
id |
int
|
| 返回(Returns) | |
|---|---|
View |
The view if found or null otherwise. |
AppCompatDelegate getDelegate ()
| 返回(Returns) | |
|---|---|
AppCompatDelegate |
The AppCompatDelegate being used by this Activity. |
ActionBarDrawerToggle.Delegate getDrawerToggleDelegate ()
| 返回(Returns) | |
|---|---|
ActionBarDrawerToggle.Delegate |
|
Resources getResources ()
返回应用程序包的资源实例。
注意:此方法的实现应该返回与由getAssets()返回的AssetManager实例一致的资源实例。 例如,他们应该共享相同的Configuration对象。
| 返回(Returns) | |
|---|---|
Resources |
a Resources instance for the application's package |
ActionBar getSupportActionBar ()
支持库版本 getActionBar() 。
检索对此活动的ActionBar的引用。
| 返回(Returns) | |
|---|---|
ActionBar |
The Activity's ActionBar, or null if it does not have one. |
Intent getSupportParentActivityIntent ()
获取一个Intent ,它将启动由应用程序清单中sourceActivity的PARENT_ACTIVITY <meta-data>元素指定的显式目标活动。 如果设备运行Jellybean或更新,则android:parentActivityName属性将首选(如果存在)。
| 返回(Returns) | |
|---|---|
Intent |
a new Intent targeting the defined parent activity of sourceActivity |
void onConfigurationChanged (Configuration newConfig)
调度配置更改为所有片段。
| 参数(Parameters) | |
|---|---|
newConfig |
Configuration: The new device configuration. |
void onContentChanged ()
只要屏幕的内容视图发生变化(由于调用 Window.setContentView或 Window.addContentView ), Window.setContentView调用此钩子。
void onCreateSupportNavigateUpTaskStack (TaskStackBuilder builder)
支持版本onCreateNavigateUpTaskStack(android.app.TaskStackBuilder) 。 此方法将在所有平台版本上调用。 定义将在不同任务的向上导航期间生成的合成任务堆栈。
此方法的默认实现将清单中指定的此活动的父链添加到提供的TaskStackBuilder 。 应用程序可以选择重写此方法,以不同的方式构建所需的任务堆栈。
此方法将通过的默认实现调用 onNavigateUp()如果 shouldUpRecreateTask(android.content.Intent)返回true时返回的意图提供 getParentActivityIntent() 。
希望向清单定义的父堆栈提供额外Intent参数的应用程序应覆盖 onPrepareSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder) 。
| 参数(Parameters) | |
|---|---|
builder |
TaskStackBuilder: An empty TaskStackBuilder - the application should add intents representing the desired task stack |
boolean onMenuItemSelected (int featureId,
MenuItem item)
将上下文和选项菜单分派给片段。
| 参数(Parameters) | |
|---|---|
featureId |
int: The panel that the menu is in. |
item |
MenuItem: The menu item that was selected. |
| 返回(Returns) | |
|---|---|
boolean |
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). |
boolean onMenuOpened (int featureId,
Menu menu)
用户打开面板菜单时调用。 当菜单从一种类型更改为另一种时(例如,从图标菜单变为扩展菜单),也可能会调用此功能。
请注意:AppCompat使用它自己的功能ID作为操作栏: FEATURE_SUPPORT_ACTION_BAR 。
| 参数(Parameters) | |
|---|---|
featureId |
int: The panel that the menu is in. |
menu |
Menu: The menu that is opened. |
| 返回(Returns) | |
|---|---|
boolean |
The default implementation returns true. |
void onPanelClosed (int featureId,
Menu menu)
在片段上调用onOptionsMenuClosed()。
请注意:AppCompat使用它自己的功能ID作为操作栏: FEATURE_SUPPORT_ACTION_BAR 。
| 参数(Parameters) | |
|---|---|
featureId |
int: The panel that is being displayed. |
menu |
Menu: If onCreatePanelView() returned null, this is the Menu being displayed in the panel. |
void onPrepareSupportNavigateUpTaskStack (TaskStackBuilder builder)
支持版本onPrepareNavigateUpTaskStack(android.app.TaskStackBuilder) 。 此方法将在所有平台版本上调用。 准备将从不同任务的Up导航过程中生成的合成任务堆栈。
该方法接收TaskStackBuilder ,其构建的一系列意图由onCreateSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder)生成。 如果在启动新任务之前应将任何额外数据添加到这些意向中,则应用程序应覆盖此方法并在此处添加该数据。
| 参数(Parameters) | |
|---|---|
builder |
TaskStackBuilder: A TaskStackBuilder that has been populated with Intents by onCreateNavigateUpTaskStack. |
void onSupportActionModeFinished (ActionMode mode)
通知活动已完成支持操作模式。 覆盖此方法的Activity子类应调用超类实现。
| 参数(Parameters) | |
|---|---|
mode |
ActionMode: The action mode that just finished. |
void onSupportActionModeStarted (ActionMode mode)
通知活动支持操作模式已启动。 覆盖此方法的Activity子类应调用超类实现。
| 参数(Parameters) | |
|---|---|
mode |
ActionMode: The new action mode. |
boolean onSupportNavigateUp ()
只要用户选择在应用程序的活动层次结构中从操作栏中向上导航,就会调用此方法。
如果在此活动的清单中指定了父级或其活动别名,则将自动处理默认的Up导航。 有关如何指定父getSupportParentActivityIntent() ,请参阅getSupportParentActivityIntent() 。 如果父链上的任何活动需要额外的Intent参数,则Activity子类应重写方法onPrepareSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder)以提供这些参数。
见 Tasks and Back Stack从开发者指南和 Navigation从设计指南有关应用程序内浏览更多信息。
见 TaskStackBuilder类和活性的方法 getSupportParentActivityIntent() , supportShouldUpRecreateTask(android.content.Intent) ,并 supportNavigateUpTo(android.content.Intent)求助实现自定义向上导航。
| 返回(Returns) | |
|---|---|
boolean |
true if Up navigation completed successfully and this Activity was finished, false otherwise. |
ActionMode onWindowStartingSupportActionMode (ActionMode.Callback callback)
当此窗口的支持动作模式正在启动时调用。 给回调提供了一个机会,以自己独特而美丽的方式处理动作模式。 如果此方法返回null,则系统可以选择一种呈现模式的方式或根本不选择启动模式。
| 参数(Parameters) | |
|---|---|
callback |
ActionMode.Callback: Callback to control the lifecycle of this action mode |
| 返回(Returns) | |
|---|---|
ActionMode |
The ActionMode that was started, or null if the system should present it |
void setContentView (View view)
将活动内容设置为显式视图。 该视图直接放置在活动的视图层次结构中。 它本身可能是一个复杂的视图层次结构。 调用此方法时,指定视图的布局参数将被忽略。 视图的宽度和高度都默认设置为MATCH_PARENT 。 要使用自己的布局参数,请调用setContentView(android.view.View, android.view.ViewGroup.LayoutParams) 。
| 参数(Parameters) | |
|---|---|
view |
View: The desired content to display. |
void setContentView (int layoutResID)
设置布局资源的活动内容。 资源将被夸大,将所有顶级视图添加到活动中。
| 参数(Parameters) | |
|---|---|
layoutResID |
int: Resource ID to be inflated. |
void setContentView (View view, ViewGroup.LayoutParams params)
将活动内容设置为显式视图。 该视图直接放置在活动的视图层次结构中。 它本身可能是一个复杂的视图层次结构。
| 参数(Parameters) | |
|---|---|
view |
View: The desired content to display. |
params |
ViewGroup.LayoutParams: Layout parameters for the view. |
void setSupportActionBar (Toolbar toolbar)
设置 Toolbar作为此活动窗口的 ActionBar 。
当设置为非空值时, getActionBar()方法将返回一个ActionBar对象,该对象可用于控制给定的工具栏,就像它是传统的窗口装饰操作栏一样。 工具栏的菜单将填充活动的选项菜单,导航按钮将通过标准的home菜单选择操作进行布线。
为了在活动的窗口内容中使用工具栏,应用程序不能请求窗口功能 FEATURE_SUPPORT_ACTION_BAR 。
| 参数(Parameters) | |
|---|---|
toolbar |
Toolbar: Toolbar to set as the Activity's action bar, or null to clear it |
void setSupportProgress (int progress)
此方法已弃用。
AppCompat中不再提供进度条。
| 参数(Parameters) | |
|---|---|
progress |
int
|
void setSupportProgressBarIndeterminate (boolean indeterminate)
此方法已弃用。
AppCompat中不再提供进度条。
| 参数(Parameters) | |
|---|---|
indeterminate |
boolean
|
void setSupportProgressBarIndeterminateVisibility (boolean visible)
此方法已弃用。
AppCompat中不再提供进度条。
| 参数(Parameters) | |
|---|---|
visible |
boolean
|
void setSupportProgressBarVisibility (boolean visible)
此方法已弃用。
AppCompat中不再提供进度条。
| 参数(Parameters) | |
|---|---|
visible |
boolean
|
void setTheme (int resid)
为此上下文设置基本主题。 请注意,应在上下文中实例化任何视图之前调用setContentView(View) (例如,在调用setContentView(View)或inflate(int, ViewGroup)之前)。
| 参数(Parameters) | |
|---|---|
resid |
int: The style resource describing the theme. |
ActionMode startSupportActionMode (ActionMode.Callback callback)
启动一个动作模式。
| 参数(Parameters) | |
|---|---|
callback |
ActionMode.Callback: Callback that will manage lifecycle events for this context mode |
| 返回(Returns) | |
|---|---|
ActionMode |
The ContextMode that was started, or null if it was canceled |
void supportInvalidateOptionsMenu ()
支持库版本 invalidateOptionsMenu() 。
使活动的选项菜单失效。 这将导致菜单的相关演示在下次请求菜单时通过调用onCreateOptionsMenu和onPrepareOptionsMenu完全更新。
void supportNavigateUpTo (Intent upIntent)
从sourceActivity导航到由upIntent指定的活动,在流程中完成sourceActivity。 upIntent将使用此方法设置的标志FLAG_ACTIVITY_CLEAR_TOP ,以及Android设计指南中概述的正确导航所需的其他标志。
在与目的地相同的任务内执行导航时应使用此方法。 如果在某些情况下向上导航应该跨越任务,请参阅supportShouldUpRecreateTask(android.content.Intent) 。
| 参数(Parameters) | |
|---|---|
upIntent |
Intent: An intent representing the target destination for up navigation |
boolean supportRequestWindowFeature (int featureId)
启用扩展支持库窗口功能。
这是拨打 getWindow().requestFeature()的方便之 getWindow().requestFeature() 。
| 参数(Parameters) | |
|---|---|
featureId |
int: The desired feature as defined in Window or WindowCompat. |
| 返回(Returns) | |
|---|---|
boolean |
Returns true if the requested feature is supported and now enabled. |
boolean supportShouldUpRecreateTask (Intent targetIntent)
如果sourceActivity在使用targetIntent导航'up'时重新创建任务,则返回true。
如果此方法返回false,则应用程序可以使用相同的参数轻松地调用supportNavigateUpTo(android.content.Intent)以正确执行导航。 如果此方法返回false,则应用程序应通过使用TaskStackBuilder或其他类似的机制来合成新的任务堆栈以执行导航。
| 参数(Parameters) | |
|---|---|
targetIntent |
Intent: 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 |
void onCreate (Bundle savedInstanceState)
执行所有片段和加载器的初始化。
| 参数(Parameters) | |
|---|---|
savedInstanceState |
Bundle: 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. |
void onDestroy ()
销毁所有碎片和装载机。
void onPostCreate (Bundle savedInstanceState)
当活动启动完成时调用(在onStart()和onRestoreInstanceState(Bundle)之后)。 应用程序通常不会实现这种方法; 它旨在让系统类在应用程序代码运行后进行最终初始化。
派生类必须调用超类的这个方法的实现。 如果他们不这样做,就会抛出异常。
| 参数(Parameters) | |
|---|---|
savedInstanceState |
Bundle: 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. |
void onPostResume ()
将onResume()分派给片段。
void onSaveInstanceState (Bundle outState)
保存所有适当的片段状态。
| 参数(Parameters) | |
|---|---|
outState |
Bundle: Bundle in which to place your saved state. |
void onStop ()
将onStop()分派给所有片段。 确保所有装载机停止。
void onTitleChanged (CharSequence title, int color)
| 参数(Parameters) | |
|---|---|
title |
CharSequence
|
color |
int
|