public
class
DrawerLayout
extends ViewGroup
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v4.widget.DrawerLayout |
DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.
Drawer positioning and layout is controlled using the android:layout_gravity
attribute on child views corresponding to which side of the view you want the drawer
to emerge from: left or right (or start/end on platform versions that support layout direction.)
Note that you can only have one drawer view for each vertical edge of the window. If your
layout configures more than one drawer view per vertical edge of the window, an exception will
be thrown at runtime.
To use a DrawerLayout, position your primary content view as the first child with
width and height of match_parent
and no layout_gravity>
.
Add drawers as child views after the main content view and set the layout_gravity
appropriately. Drawers commonly use match_parent
for height with a fixed width.
DrawerLayout.DrawerListener
can be used to monitor the state and motion of drawer views.
Avoid performing expensive operations such as layout during animation as it can cause
stuttering; try to perform expensive operations during the STATE_IDLE
state.
DrawerLayout.SimpleDrawerListener
offers default/no-op implementations of each callback method.
As per the Android Design guide, any drawers positioned to the left/start should always contain content for navigating around the application, whereas any drawers positioned to the right/end should always contain actions to take on the current content. This preserves the same navigation left, actions right structure present in the Action Bar and elsewhere.
For more information about how to use DrawerLayout, read Creating a Navigation Drawer.
Nested classes | |
---|---|
interface |
DrawerLayout.DrawerListener
Listener for monitoring events about drawers. |
class |
DrawerLayout.LayoutParams
|
class |
DrawerLayout.SavedState
State persisted across instances |
class |
DrawerLayout.SimpleDrawerListener
Stub/no-op implementations of all methods of |
Inherited XML attributes | |
---|---|
From
class
android.view.ViewGroup
| |
From
class
android.view.View
|
Constants | |
---|---|
int |
LOCK_MODE_LOCKED_CLOSED
The drawer is locked closed. |
int |
LOCK_MODE_LOCKED_OPEN
The drawer is locked open. |
int |
LOCK_MODE_UNDEFINED
The drawer's lock state is reset to default. |
int |
LOCK_MODE_UNLOCKED
The drawer is unlocked. |
int |
STATE_DRAGGING
Indicates that a drawer is currently being dragged by the user. |
int |
STATE_IDLE
Indicates that any drawers are in an idle, settled state. |
int |
STATE_SETTLING
Indicates that a drawer is in the process of settling to a final position. |
Inherited constants |
---|
From
class
android.view.ViewGroup
|
From
class
android.view.View
|
Inherited fields |
---|
From
class
android.view.View
|
Public constructors | |
---|---|
DrawerLayout(Context context)
|
|
DrawerLayout(Context context, AttributeSet attrs)
|
|
DrawerLayout(Context context, AttributeSet attrs, int defStyle)
|
Public methods | |
---|---|
void
|
addDrawerListener(DrawerLayout.DrawerListener listener)
Adds the specified listener to the list of listeners that will be notified of drawer events. |
void
|
addFocusables(ArrayList<View> views, int direction, int focusableMode)
Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. |
void
|
addView(View child, int index, ViewGroup.LayoutParams params)
Adds a child view with the specified layout parameters. |
void
|
closeDrawer(View drawerView)
Close the specified drawer view by animating it into view. |
void
|
closeDrawer(int gravity)
Close the specified drawer by animating it out of view. |
void
|
closeDrawer(View drawerView, boolean animate)
Close the specified drawer view. |
void
|
closeDrawer(int gravity, boolean animate)
Close the specified drawer. |
void
|
closeDrawers()
Close all currently open drawer views by animating them out of view. |
void
|
computeScroll()
Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. |
ViewGroup.LayoutParams
|
generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set. |
float
|
getDrawerElevation()
The base elevation of the drawer(s) relative to the parent, in pixels. |
int
|
getDrawerLockMode(int edgeGravity)
Check the lock mode of the drawer with the given gravity. |
int
|
getDrawerLockMode(View drawerView)
Check the lock mode of the given drawer view. |
CharSequence
|
getDrawerTitle(int edgeGravity)
Returns the title of the drawer with the given gravity. |
Drawable
|
getStatusBarBackgroundDrawable()
Gets the drawable used to draw in the insets area for the status bar. |
boolean
|
isDrawerOpen(View drawer)
Check if the given drawer view is currently in an open state. |
boolean
|
isDrawerOpen(int drawerGravity)
Check if the given drawer view is currently in an open state. |
boolean
|
isDrawerVisible(View drawer)
Check if a given drawer view is currently visible on-screen. |
boolean
|
isDrawerVisible(int drawerGravity)
Check if a given drawer view is currently visible on-screen. |
void
|
onDraw(Canvas c)
Implement this to do your drawing. |
boolean
|
onInterceptTouchEvent(MotionEvent ev)
Implement this method to intercept all touch screen motion events. |
boolean
|
onKeyDown(int keyCode, KeyEvent event)
Default implementation of |
boolean
|
onKeyUp(int keyCode, KeyEvent event)
Default implementation of |
void
|
onRtlPropertiesChanged(int layoutDirection)
Called when any RTL property (layout direction or text direction or text alignment) has been changed. |
boolean
|
onTouchEvent(MotionEvent ev)
Implement this method to handle touch screen motion events. |
void
|
openDrawer(View drawerView, boolean animate)
Open the specified drawer view. |
void
|
openDrawer(View drawerView)
Open the specified drawer view by animating it into view. |
void
|
openDrawer(int gravity)
Open the specified drawer by animating it out of view. |
void
|
openDrawer(int gravity, boolean animate)
Open the specified drawer. |
void
|
removeDrawerListener(DrawerLayout.DrawerListener listener)
Removes the specified listener from the list of listeners that will be notified of drawer events. |
void
|
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
Called when a child does not want this parent and its ancestors to
intercept touch events with
|
void
|
requestLayout()
Call this when something has changed which has invalidated the layout of this view. |
void
|
setDrawerElevation(float elevation)
Sets the base elevation of the drawer(s) relative to the parent, in pixels. |
void
|
setDrawerListener(DrawerLayout.DrawerListener listener)
This method is deprecated.
Use |
void
|
setDrawerLockMode(int lockMode, View drawerView)
Enable or disable interaction with the given drawer. |
void
|
setDrawerLockMode(int lockMode)
Enable or disable interaction with all drawers. |
void
|
setDrawerLockMode(int lockMode, int edgeGravity)
Enable or disable interaction with the given drawer. |
void
|
setDrawerShadow(int resId, int gravity)
Set a simple drawable used for the left or right shadow. |
void
|
setDrawerShadow(Drawable shadowDrawable, int gravity)
Set a simple drawable used for the left or right shadow. |
void
|
setDrawerTitle(int edgeGravity, CharSequence title)
Sets the title of the drawer with the given gravity. |
void
|
setScrimColor(int color)
Set a color to use for the scrim that obscures primary content while a drawer is open. |
void
|
setStatusBarBackground(Drawable bg)
Set a drawable to draw in the insets area for the status bar. |
void
|
setStatusBarBackground(int resId)
Set a drawable to draw in the insets area for the status bar. |
void
|
setStatusBarBackgroundColor(int color)
Set a drawable to draw in the insets area for the status bar. |
Protected methods | |
---|---|
boolean
|
checkLayoutParams(ViewGroup.LayoutParams p)
|
boolean
|
drawChild(Canvas canvas, View child, long drawingTime)
Draw one child of this View Group. |
ViewGroup.LayoutParams
|
generateDefaultLayoutParams()
Returns a set of default layout parameters. |
ViewGroup.LayoutParams
|
generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params. |
void
|
onAttachedToWindow()
This is called when the view is attached to a window. |
void
|
onDetachedFromWindow()
This is called when the view is detached from a window. |
void
|
onLayout(boolean changed, int l, int t, int r, int b)
Called from layout when this view should assign a size and position to each of its children. |
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
Measure the view and its content to determine the measured width and the measured height. |
void
|
onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by |
Parcelable
|
onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. |
Inherited methods | |
---|---|
From
class
android.view.ViewGroup
| |
From
class
android.view.View
| |
From
class
java.lang.Object
| |
From
interface
android.view.ViewParent
| |
From
interface
android.view.ViewManager
| |
From
interface
android.graphics.drawable.Drawable.Callback
| |
From
interface
android.view.KeyEvent.Callback
| |
From
interface
android.view.accessibility.AccessibilityEventSource
|
int LOCK_MODE_LOCKED_CLOSED
The drawer is locked closed. The user may not open it, though the app may open it programmatically.
Constant Value: 1 (0x00000001)
int LOCK_MODE_LOCKED_OPEN
The drawer is locked open. The user may not close it, though the app may close it programmatically.
Constant Value: 2 (0x00000002)
int LOCK_MODE_UNDEFINED
The drawer's lock state is reset to default.
Constant Value: 3 (0x00000003)
int LOCK_MODE_UNLOCKED
The drawer is unlocked.
Constant Value: 0 (0x00000000)
int STATE_DRAGGING
Indicates that a drawer is currently being dragged by the user.
Constant Value: 1 (0x00000001)
int STATE_IDLE
Indicates that any drawers are in an idle, settled state. No animation is in progress.
Constant Value: 0 (0x00000000)
int STATE_SETTLING
Indicates that a drawer is in the process of settling to a final position.
Constant Value: 2 (0x00000002)
DrawerLayout (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context
|
attrs |
AttributeSet
|
DrawerLayout (Context context, AttributeSet attrs, int defStyle)
Parameters | |
---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyle |
int
|
void addDrawerListener (DrawerLayout.DrawerListener listener)
Adds the specified listener to the list of listeners that will be notified of drawer events.
Parameters | |
---|---|
listener |
DrawerLayout.DrawerListener :
Listener to notify when drawer events occur. |
See also:
void addFocusables (ArrayList<View> views, int direction, int focusableMode)
Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. This method adds all focusable views regardless if we are in touch mode or only views focusable in touch mode if we are in touch mode or only views that can take accessibility focus if accessibility is enabled depending on the focusable mode parameter.
Parameters | |
---|---|
views |
ArrayList :
Focusable views found so far or null if all we are interested is
the number of focusables. |
direction |
int :
The direction of the focus. |
focusableMode |
int :
The type of focusables to be added. |
void addView (View child, int index, ViewGroup.LayoutParams params)
Adds a child view with the specified layout parameters.
Note: do not invoke this method from
draw(android.graphics.Canvas)
, onDraw(android.graphics.Canvas)
,
dispatchDraw(android.graphics.Canvas)
or any related method.
Parameters | |
---|---|
child |
View :
the child view to add |
index |
int :
the position at which to add the child or -1 to add last |
params |
ViewGroup.LayoutParams :
the layout parameters to set on the child
|
void closeDrawer (View drawerView)
Close the specified drawer view by animating it into view.
Parameters | |
---|---|
drawerView |
View :
Drawer view to close
|
void closeDrawer (int gravity)
Close the specified drawer by animating it out of view.
Parameters | |
---|---|
gravity |
int :
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
GravityCompat.START or GravityCompat.END may also be used.
|
void closeDrawer (View drawerView, boolean animate)
Close the specified drawer view.
Parameters | |
---|---|
drawerView |
View :
Drawer view to close |
animate |
boolean :
Whether closing of the drawer should be animated.
|
void closeDrawer (int gravity, boolean animate)
Close the specified drawer.
Parameters | |
---|---|
gravity |
int :
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
GravityCompat.START or GravityCompat.END may also be used. |
animate |
boolean :
Whether closing of the drawer should be animated.
|
void closeDrawers ()
Close all currently open drawer views by animating them out of view.
void computeScroll ()
Called by a parent to request that a child update its values for mScrollX
and mScrollY if necessary. This will typically be done if the child is
animating a scroll using a Scroller
object.
ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
Parameters | |
---|---|
attrs |
AttributeSet :
the attributes to build the layout parameters from |
Returns | |
---|---|
ViewGroup.LayoutParams |
an instance of ViewGroup.LayoutParams or one
of its descendants
|
float getDrawerElevation ()
The base elevation of the drawer(s) relative to the parent, in pixels. Note that the elevation change is only supported in API 21 and above. For unsupported API levels, 0 will be returned as the elevation.
Returns | |
---|---|
float |
The base depth position of the view, in pixels. |
int getDrawerLockMode (int edgeGravity)
Check the lock mode of the drawer with the given gravity.
Parameters | |
---|---|
edgeGravity |
int :
Gravity of the drawer to check |
Returns | |
---|---|
int |
one of LOCK_MODE_UNLOCKED , LOCK_MODE_LOCKED_CLOSED or
LOCK_MODE_LOCKED_OPEN .
|
int getDrawerLockMode (View drawerView)
Check the lock mode of the given drawer view.
Parameters | |
---|---|
drawerView |
View :
Drawer view to check lock mode |
Returns | |
---|---|
int |
one of LOCK_MODE_UNLOCKED , LOCK_MODE_LOCKED_CLOSED or
LOCK_MODE_LOCKED_OPEN .
|
CharSequence getDrawerTitle (int edgeGravity)
Returns the title of the drawer with the given gravity.
Parameters | |
---|---|
edgeGravity |
int :
Gravity.LEFT, RIGHT, START or END. Expresses which
drawer to return the title for. |
Returns | |
---|---|
CharSequence |
The title of the drawer, or null if none set. |
See also:
Drawable getStatusBarBackgroundDrawable ()
Gets the drawable used to draw in the insets area for the status bar.
Returns | |
---|---|
Drawable |
The status bar background drawable, or null if none set |
boolean isDrawerOpen (View drawer)
Check if the given drawer view is currently in an open state.
To be considered "open" the drawer must have settled into its fully
visible state. To check for partial visibility use
isDrawerVisible(android.view.View)
.
Parameters | |
---|---|
drawer |
View :
Drawer view to check |
Returns | |
---|---|
boolean |
true if the given drawer view is in an open state |
See also:
boolean isDrawerOpen (int drawerGravity)
Check if the given drawer view is currently in an open state. To be considered "open" the drawer must have settled into its fully visible state. If there is no drawer with the given gravity this method will return false.
Parameters | |
---|---|
drawerGravity |
int :
Gravity of the drawer to check |
Returns | |
---|---|
boolean |
true if the given drawer view is in an open state |
boolean isDrawerVisible (View drawer)
Check if a given drawer view is currently visible on-screen. The drawer may be only peeking onto the screen, fully extended, or anywhere inbetween.
Parameters | |
---|---|
drawer |
View :
Drawer view to check |
Returns | |
---|---|
boolean |
true if the given drawer is visible on-screen |
See also:
boolean isDrawerVisible (int drawerGravity)
Check if a given drawer view is currently visible on-screen. The drawer may be only peeking onto the screen, fully extended, or anywhere in between. If there is no drawer with the given gravity this method will return false.
Parameters | |
---|---|
drawerGravity |
int :
Gravity of the drawer to check |
Returns | |
---|---|
boolean |
true if the given drawer is visible on-screen |
void onDraw (Canvas c)
Implement this to do your drawing.
Parameters | |
---|---|
c |
Canvas :
the canvas on which the background will be drawn
|
boolean onInterceptTouchEvent (MotionEvent ev)
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.
Using this function takes some care, as it has a fairly complicated
interaction with View.onTouchEvent(MotionEvent)
, and using it requires implementing
that method as well as this one in the correct way. Events will be
received in the following order:
ACTION_CANCEL
, and all further
events will be delivered to your onTouchEvent() method and no longer
appear here.
Parameters | |
---|---|
ev |
MotionEvent :
The motion event being dispatched down the hierarchy. |
Returns | |
---|---|
boolean |
Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here. |
boolean onKeyDown (int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyDown()
: perform press of the view
when KEYCODE_DPAD_CENTER
or KEYCODE_ENTER
is released, if the view is enabled and clickable.
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
Parameters | |
---|---|
keyCode |
int :
a key code that represents the button pressed, from
KeyEvent |
event |
KeyEvent :
the KeyEvent object that defines the button action
|
Returns | |
---|---|
boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
boolean onKeyUp (int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyUp()
: perform clicking of the view
when KEYCODE_DPAD_CENTER
, KEYCODE_ENTER
or KEYCODE_SPACE
is released.
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
Parameters | |
---|---|
keyCode |
int :
A key code that represents the button pressed, from
KeyEvent . |
event |
KeyEvent :
The KeyEvent object that defines the button action.
|
Returns | |
---|---|
boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
void onRtlPropertiesChanged (int layoutDirection)
Called when any RTL property (layout direction or text direction or text alignment) has been changed. Subclasses need to override this method to take care of cached information that depends on the resolved layout direction, or to inform child views that inherit their layout direction. The default implementation does nothing.
Parameters | |
---|---|
layoutDirection |
int :
the direction of the layout |
boolean onTouchEvent (MotionEvent ev)
Implement this method to handle touch screen motion events.
If this method is used to detect click actions, it is recommended that
the actions be performed by implementing and calling
performClick()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
Parameters | |
---|---|
ev |
MotionEvent :
The motion event. |
Returns | |
---|---|
boolean |
True if the event was handled, false otherwise. |
void openDrawer (View drawerView, boolean animate)
Open the specified drawer view.
Parameters | |
---|---|
drawerView |
View :
Drawer view to open |
animate |
boolean :
Whether opening of the drawer should be animated.
|
void openDrawer (View drawerView)
Open the specified drawer view by animating it into view.
Parameters | |
---|---|
drawerView |
View :
Drawer view to open
|
void openDrawer (int gravity)
Open the specified drawer by animating it out of view.
Parameters | |
---|---|
gravity |
int :
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
GravityCompat.START or GravityCompat.END may also be used.
|
void openDrawer (int gravity, boolean animate)
Open the specified drawer.
Parameters | |
---|---|
gravity |
int :
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.
GravityCompat.START or GravityCompat.END may also be used. |
animate |
boolean :
Whether opening of the drawer should be animated.
|
void removeDrawerListener (DrawerLayout.DrawerListener listener)
Removes the specified listener from the list of listeners that will be notified of drawer events.
Parameters | |
---|---|
listener |
DrawerLayout.DrawerListener :
Listener to remove from being notified of drawer events |
See also:
void requestDisallowInterceptTouchEvent (boolean disallowIntercept)
Called when a child does not want this parent and its ancestors to
intercept touch events with
onInterceptTouchEvent(MotionEvent)
.
This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.
Parameters | |
---|---|
disallowIntercept |
boolean :
True if the child does not want the parent to
intercept touch events.
|
void requestLayout ()
Call this when something has changed which has invalidated the
layout of this view. This will schedule a layout pass of the view
tree. This should not be called while the view hierarchy is currently in a layout
pass (isInLayout()
. If layout is happening, the request may be honored at the
end of the current layout pass (and then layout will run again) or after the current
frame is drawn and the next layout occurs.
Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.
void setDrawerElevation (float elevation)
Sets the base elevation of the drawer(s) relative to the parent, in pixels. Note that the elevation change is only supported in API 21 and above.
Parameters | |
---|---|
elevation |
float :
The base depth position of the view, in pixels.
|
void setDrawerListener (DrawerLayout.DrawerListener listener)
This method is deprecated.
Use addDrawerListener(DrawerListener)
Set a listener to be notified of drawer events. Note that this method is deprecated
and you should use addDrawerListener(DrawerListener)
to add a listener and
removeDrawerListener(DrawerListener)
to remove a registered listener.
Parameters | |
---|---|
listener |
DrawerLayout.DrawerListener :
Listener to notify when drawer events occur |
void setDrawerLockMode (int lockMode, View drawerView)
Enable or disable interaction with the given drawer.
This allows the application to restrict the user's ability to open or close
the given drawer. DrawerLayout will still respond to calls to openDrawer(int)
,
closeDrawer(int)
and friends if a drawer is locked.
Locking a drawer open or closed will implicitly open or close that drawer as appropriate.
Parameters | |
---|---|
lockMode |
int :
The new lock mode for the given drawer. One of LOCK_MODE_UNLOCKED ,
LOCK_MODE_LOCKED_CLOSED or LOCK_MODE_LOCKED_OPEN . |
drawerView |
View :
The drawer view to change the lock mode for |
void setDrawerLockMode (int lockMode)
Enable or disable interaction with all drawers.
This allows the application to restrict the user's ability to open or close
any drawer within this layout. DrawerLayout will still respond to calls to
openDrawer(int)
, closeDrawer(int)
and friends if a drawer is locked.
Locking drawers open or closed will implicitly open or close any drawers as appropriate.
Parameters | |
---|---|
lockMode |
int :
The new lock mode for the given drawer. One of LOCK_MODE_UNLOCKED ,
LOCK_MODE_LOCKED_CLOSED or LOCK_MODE_LOCKED_OPEN .
|
void setDrawerLockMode (int lockMode, int edgeGravity)
Enable or disable interaction with the given drawer.
This allows the application to restrict the user's ability to open or close
the given drawer. DrawerLayout will still respond to calls to openDrawer(int)
,
closeDrawer(int)
and friends if a drawer is locked.
Locking a drawer open or closed will implicitly open or close that drawer as appropriate.
Parameters | |
---|---|
lockMode |
int :
The new lock mode for the given drawer. One of LOCK_MODE_UNLOCKED ,
LOCK_MODE_LOCKED_CLOSED or LOCK_MODE_LOCKED_OPEN . |
edgeGravity |
int :
Gravity.LEFT, RIGHT, START or END.
Expresses which drawer to change the mode for. |
void setDrawerShadow (int resId, int gravity)
Set a simple drawable used for the left or right shadow. The drawable provided must have a nonzero intrinsic width. For API 21 and above, an elevation will be set on the drawer instead of the drawable provided.
Note that for better support for both left-to-right and right-to-left layout
directions, a drawable for RTL layout (in additional to the one in LTR layout) can be
defined with a resource qualifier "ldrtl" for API 17 and above with the gravity
START
. Alternatively, for API 23 and above, the drawable can
auto-mirrored such that the drawable will be mirrored in RTL layout.
Parameters | |
---|---|
resId |
int :
Resource id of a shadow drawable to use at the edge of a drawer |
gravity |
int :
Which drawer the shadow should apply to
|
void setDrawerShadow (Drawable shadowDrawable, int gravity)
Set a simple drawable used for the left or right shadow. The drawable provided must have a nonzero intrinsic width. For API 21 and above, an elevation will be set on the drawer instead of the drawable provided.
Note that for better support for both left-to-right and right-to-left layout
directions, a drawable for RTL layout (in additional to the one in LTR layout) can be
defined with a resource qualifier "ldrtl" for API 17 and above with the gravity
START
. Alternatively, for API 23 and above, the drawable can
auto-mirrored such that the drawable will be mirrored in RTL layout.
Parameters | |
---|---|
shadowDrawable |
Drawable :
Shadow drawable to use at the edge of a drawer |
gravity |
int :
Which drawer the shadow should apply to
|
void setDrawerTitle (int edgeGravity, CharSequence title)
Sets the title of the drawer with the given gravity.
When accessibility is turned on, this is the title that will be used to identify the drawer to the active accessibility service.
Parameters | |
---|---|
edgeGravity |
int :
Gravity.LEFT, RIGHT, START or END. Expresses which
drawer to set the title for. |
title |
CharSequence :
The title for the drawer.
|
void setScrimColor (int color)
Set a color to use for the scrim that obscures primary content while a drawer is open.
Parameters | |
---|---|
color |
int :
Color to use in 0xAARRGGBB format.
|
void setStatusBarBackground (Drawable bg)
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
Parameters | |
---|---|
bg |
Drawable :
Background drawable to draw behind the status bar
|
void setStatusBarBackground (int resId)
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
Parameters | |
---|---|
resId |
int :
Resource id of a background drawable to draw behind the status bar
|
void setStatusBarBackgroundColor (int color)
Set a drawable to draw in the insets area for the status bar. Note that this will only be activated if this DrawerLayout fitsSystemWindows.
Parameters | |
---|---|
color |
int :
Color to use as a background drawable to draw behind the status bar
in 0xAARRGGBB format.
|
boolean checkLayoutParams (ViewGroup.LayoutParams p)
Parameters | |
---|---|
p |
ViewGroup.LayoutParams
|
Returns | |
---|---|
boolean |
boolean drawChild (Canvas canvas, View child, long drawingTime)
Draw one child of this View Group. This method is responsible for getting the canvas in the right state. This includes clipping, translating so that the child's scrolled origin is at 0, 0, and applying any animation transformations.
Parameters | |
---|---|
canvas |
Canvas :
The canvas on which to draw the child |
child |
View :
Who to draw |
drawingTime |
long :
The time at which draw is occurring |
Returns | |
---|---|
boolean |
True if an invalidate() was issued |
ViewGroup.LayoutParams generateDefaultLayoutParams ()
Returns a set of default layout parameters. These parameters are requested
when the View passed to addView(View)
has no layout parameters
already set. If null is returned, an exception is thrown from addView.
Returns | |
---|---|
ViewGroup.LayoutParams |
a set of default layout parameters or null |
ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
When a ViewGroup is passed a View whose layout params do not pass the test of
checkLayoutParams(android.view.ViewGroup.LayoutParams)
, this method
is invoked. This method should return a new set of layout params suitable for
this ViewGroup, possibly by copying the appropriate attributes from the
specified set of layout params.
Parameters | |
---|---|
p |
ViewGroup.LayoutParams :
The layout parameters to convert into a suitable set of layout parameters
for this ViewGroup. |
Returns | |
---|---|
ViewGroup.LayoutParams |
an instance of ViewGroup.LayoutParams or one
of its descendants
|
void onAttachedToWindow ()
This is called when the view is attached to a window. At this point it
has a Surface and will start drawing. Note that this function is
guaranteed to be called before onDraw(android.graphics.Canvas)
,
however it may be called any time before the first onDraw -- including
before or after onMeasure(int, int)
.
void onDetachedFromWindow ()
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
void onLayout (boolean changed, int l, int t, int r, int b)
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
Parameters | |
---|---|
changed |
boolean :
This is a new size or position for this view |
l |
int :
Left position, relative to parent |
t |
int :
Top position, relative to parent |
r |
int :
Right position, relative to parent |
b |
int :
Bottom position, relative to parent
|
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by measure(int, int)
and
should be overridden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int)
. Calling the superclass'
onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (getSuggestedMinimumHeight()
and
getSuggestedMinimumWidth()
).
Parameters | |
---|---|
widthMeasureSpec |
int :
horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
heightMeasureSpec |
int :
vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
void onRestoreInstanceState (Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by onSaveInstanceState()
. This function will never be called with a
null state.
Parameters | |
---|---|
state |
Parcelable :
The frozen state that had previously been returned by
onSaveInstanceState() . |
Parcelable onSaveInstanceState ()
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.
Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
Returns | |
---|---|
Parcelable |
Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null. |