public class ActionBarDrawerToggle
extends Object implements DrawerLayout.DrawerListener
| java.lang.Object | |
| android.support.v4.app.ActionBarDrawerToggle | |
这个类已被弃用。
请在support-v7-appcompat中使用ActionBarDrawerToggle。
该课程提供了一种方便的方式,将 DrawerLayout和框架 ActionBar的功能绑定在一起,以实现导航抽屉的推荐设计。
要使用 ActionBarDrawerToggle ,请在您的活动中创建一个并调用以下与您的活动回调对应的方法:
在 onRestoreInstanceState发生后,从 Activity的 onPostCreate调用 syncState()以使指示符与链接的DrawerLayout的状态同步。
ActionBarDrawerToggle可以直接用作 DrawerLayout.DrawerListener ,或者如果您已经提供了您自己的侦听器,请从您自己的每个侦听器方法中调用。
Nested classes |
|
|---|---|
interface |
ActionBarDrawerToggle.Delegate
|
interface |
ActionBarDrawerToggle.DelegateProvider 允许实现Activity返回 |
Public constructors |
|
|---|---|
ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes) 构建一个新的ActionBarDrawerToggle。 |
|
ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, boolean animate, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes) 构建一个新的ActionBarDrawerToggle。 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
isDrawerIndicatorEnabled() |
void |
onConfigurationChanged(Configuration newConfig) 该方法应始终由您的 |
void |
onDrawerClosed(View drawerView) |
void |
onDrawerOpened(View drawerView) |
void |
onDrawerSlide(View drawerView, float slideOffset) |
void |
onDrawerStateChanged(int newState) |
boolean |
onOptionsItemSelected(MenuItem item) 这种方法应该由你的 |
void |
setDrawerIndicatorEnabled(boolean enable) 启用或禁用抽屉指示器。 |
void |
setHomeAsUpIndicator(int resId) 设置向上指示器以在抽屉指示器未启用时显示。 |
void |
setHomeAsUpIndicator(Drawable indicator) 设置向上指示器以在抽屉指示器未启用时显示。 |
void |
syncState() 将抽屉指示灯/可供件状态与链接的DrawerLayout同步。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.support.v4.widget.DrawerLayout.DrawerListener
|
|
ActionBarDrawerToggle (Activity activity, DrawerLayout drawerLayout, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes)
构建一个新的ActionBarDrawerToggle。
给定的Activity将被链接到指定的DrawerLayout 。 提供的抽屉指示器在抽屉打开时会略微脱离屏幕,表明在打开状态下,抽屉在按下时将移出屏幕,在关闭状态下,抽屉在按下时将在屏幕上移动。
必须提供字符串资源来描述无障碍服务的打开/关闭抽屉动作。
| 参数(Parameters) | |
|---|---|
activity |
Activity: The Activity hosting the drawer |
drawerLayout |
DrawerLayout: The DrawerLayout to link to the given Activity's ActionBar |
drawerImageRes |
int: A Drawable resource to use as the drawer indicator |
openDrawerContentDescRes |
int: A String resource to describe the "open drawer" action for accessibility |
closeDrawerContentDescRes |
int: A String resource to describe the "close drawer" action for accessibility |
ActionBarDrawerToggle (Activity activity, DrawerLayout drawerLayout, boolean animate, int drawerImageRes, int openDrawerContentDescRes, int closeDrawerContentDescRes)
构建一个新的ActionBarDrawerToggle。
给定的Activity将链接到指定的DrawerLayout 。 提供的抽屉指示器在抽屉打开时会略微脱离屏幕,表明在打开状态下,抽屉在按下时将移出屏幕,在关闭状态下,抽屉在按下时将在屏幕上移动。
必须提供字符串资源来描述无障碍服务的打开/关闭抽屉动作。
| 参数(Parameters) | |
|---|---|
activity |
Activity: The Activity hosting the drawer |
drawerLayout |
DrawerLayout: The DrawerLayout to link to the given Activity's ActionBar |
animate |
boolean: True to animate the drawer indicator along with the drawer's position. Material apps should set this to false. |
drawerImageRes |
int: A Drawable resource to use as the drawer indicator |
openDrawerContentDescRes |
int: A String resource to describe the "open drawer" action for accessibility |
closeDrawerContentDescRes |
int: A String resource to describe the "close drawer" action for accessibility |
boolean isDrawerIndicatorEnabled ()
| 返回(Returns) | |
|---|---|
boolean |
true if the enhanced drawer indicator is enabled, false otherwise |
void onConfigurationChanged (Configuration newConfig)
该方法应始终由您的 Activity的 onConfigurationChanged方法调用。
| 参数(Parameters) | |
|---|---|
newConfig |
Configuration: The new configuration |
void onDrawerClosed (View drawerView)
DrawerLayout.DrawerListener回调方法。 如果您不直接使用ActionBarDrawerToggle实例作为DrawerLayout的侦听器,则应该从您自己的侦听器对象调用此方法。
| 参数(Parameters) | |
|---|---|
drawerView |
View: Drawer view that is now closed |
void onDrawerOpened (View drawerView)
DrawerLayout.DrawerListener回调方法。 如果您不直接使用ActionBarDrawerToggle实例作为DrawerLayout的侦听器,则应该从您自己的侦听器对象调用此方法。
| 参数(Parameters) | |
|---|---|
drawerView |
View: Drawer view that is now open |
void onDrawerSlide (View drawerView, float slideOffset)
DrawerLayout.DrawerListener回调方法。 如果您不直接使用ActionBarDrawerToggle实例作为DrawerLayout的侦听器,则应该从您自己的侦听器对象调用此方法。
| 参数(Parameters) | |
|---|---|
drawerView |
View: The child view that was moved |
slideOffset |
float: The new offset of this drawer within its range, from 0-1 |
void onDrawerStateChanged (int newState)
DrawerLayout.DrawerListener回调方法。 如果您不直接使用ActionBarDrawerToggle实例作为DrawerLayout的侦听器,则应该从您自己的侦听器对象调用此方法。
| 参数(Parameters) | |
|---|---|
newState |
int: The new drawer motion state |
boolean onOptionsItemSelected (MenuItem item)
该方法应该由您的Activity的onOptionsItemSelected方法调用。 如果它返回true,那么你的onOptionsItemSelected方法应该返回true并跳过进一步处理。
| 参数(Parameters) | |
|---|---|
item |
MenuItem: the MenuItem instance representing the selected menu item |
| 返回(Returns) | |
|---|---|
boolean |
true if the event was handled and further processing should not occur |
void setDrawerIndicatorEnabled (boolean enable)
启用或禁用抽屉指示器。 该指示器默认为启用。
当指示器被禁用时, ActionBar将恢复显示由 android.R.attr.homeAsUpIndicator属性中的 android.R.attr.homeAsUpIndicator主题提供的 Activity指示符,而不是动画抽屉字形。
| 参数(Parameters) | |
|---|---|
enable |
boolean: true to enable, false to disable |
void setHomeAsUpIndicator (int resId)
设置向上指示器以在抽屉指示器未启用时显示。
如果您将0传递给此方法,则将使用主题的默认drawable。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a drawable to use for the up indicator, or 0 to use the theme's default |
void setHomeAsUpIndicator (Drawable indicator)
设置向上指示器以在抽屉指示器未启用时显示。
如果您将 null传递给此方法,则将使用主题的默认可绘制。
| 参数(Parameters) | |
|---|---|
indicator |
Drawable: A drawable to use for the up indicator, or null to use the theme's default |
void syncState ()
将抽屉指示灯/可供件状态与链接的DrawerLayout同步。
这应该从您的Activity的onPostCreate方法中调用,以在DrawerLayout的实例状态恢复之后进行同步,以及任何其他状态可能已经发生分歧的时间,以便不通知ActionBarDrawerToggle。 (例如,如果您在一段时间内停止转发相应的抽屉事件。)