public
final
class
Snackbar
extends Object
java.lang.Object | |
↳ | android.support.design.widget.Snackbar |
Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices. Snackbars appear above all other elements on screen and only one can be displayed at a time.
They automatically disappear after a timeout or after user interaction elsewhere on the screen, particularly after interactions that summon a new surface or activity. Snackbars can be swiped off screen.
Snackbars can contain an action which is set via
setAction(CharSequence, android.view.View.OnClickListener)
.
To be notified when a snackbar has been shown or dismissed, you can provide a Snackbar.Callback
via setCallback(Callback)
.
Nested classes | |
---|---|
class |
Snackbar.Callback
Callback class for |
Constants | |
---|---|
int |
LENGTH_INDEFINITE
Show the Snackbar indefinitely. |
int |
LENGTH_LONG
Show the Snackbar for a long period of time. |
int |
LENGTH_SHORT
Show the Snackbar for a short period of time. |
Public methods | |
---|---|
void
|
dismiss()
Dismiss the |
int
|
getDuration()
Return the duration. |
View
|
getView()
Returns the |
boolean
|
isShown()
Return whether this |
boolean
|
isShownOrQueued()
Returns whether this |
static
Snackbar
|
make(View view, CharSequence text, int duration)
Make a Snackbar to display a message Snackbar will try and find a parent view to hold Snackbar's view from the value given
to |
static
Snackbar
|
make(View view, int resId, int duration)
Make a Snackbar to display a message. |
Snackbar
|
setAction(int resId, View.OnClickListener listener)
Set the action to be displayed in this |
Snackbar
|
setAction(CharSequence text, View.OnClickListener listener)
Set the action to be displayed in this |
Snackbar
|
setActionTextColor(ColorStateList colors)
Sets the text color of the action specified in
|
Snackbar
|
setActionTextColor(int color)
Sets the text color of the action specified in
|
Snackbar
|
setCallback(Snackbar.Callback callback)
Set a callback to be called when this the visibility of this |
Snackbar
|
setDuration(int duration)
Set how long to show the view for. |
Snackbar
|
setText(int resId)
Update the text in this |
Snackbar
|
setText(CharSequence message)
Update the text in this |
void
|
show()
Show the |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
int LENGTH_INDEFINITE
Show the Snackbar indefinitely. This means that the Snackbar will be displayed from the time
that is shown
until either it is dismissed, or another Snackbar is shown.
See also:
Constant Value: -2 (0xfffffffe)
int LENGTH_LONG
Show the Snackbar for a long period of time.
See also:
Constant Value: 0 (0x00000000)
int LENGTH_SHORT
Show the Snackbar for a short period of time.
See also:
Constant Value: -1 (0xffffffff)
boolean isShownOrQueued ()
Returns whether this Snackbar
is currently being shown, or is queued to be
shown next.
Returns | |
---|---|
boolean |
Snackbar make (View view, CharSequence text, int duration)
Make a Snackbar to display a message
Snackbar will try and find a parent view to hold Snackbar's view from the value given
to view
. Snackbar will walk up the view tree trying to find a suitable parent,
which is defined as a CoordinatorLayout
or the window decor's content view,
whichever comes first.
Having a CoordinatorLayout
in your view hierarchy allows Snackbar to enable
certain features, such as swipe-to-dismiss and automatically moving of widgets like
FloatingActionButton
.
Parameters | |
---|---|
view |
View :
The view to find a parent from. |
text |
CharSequence :
The text to show. Can be formatted text. |
duration |
int :
How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
|
Returns | |
---|---|
Snackbar |
Snackbar make (View view, int resId, int duration)
Make a Snackbar to display a message.
Snackbar will try and find a parent view to hold Snackbar's view from the value given
to view
. Snackbar will walk up the view tree trying to find a suitable parent,
which is defined as a CoordinatorLayout
or the window decor's content view,
whichever comes first.
Having a CoordinatorLayout
in your view hierarchy allows Snackbar to enable
certain features, such as swipe-to-dismiss and automatically moving of widgets like
FloatingActionButton
.
Parameters | |
---|---|
view |
View :
The view to find a parent from. |
resId |
int :
The resource id of the string resource to use. Can be formatted text. |
duration |
int :
How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
|
Returns | |
---|---|
Snackbar |
Snackbar setAction (int resId, View.OnClickListener listener)
Set the action to be displayed in this Snackbar
.
Parameters | |
---|---|
resId |
int :
String resource to display |
listener |
View.OnClickListener :
callback to be invoked when the action is clicked
|
Returns | |
---|---|
Snackbar |
Snackbar setAction (CharSequence text, View.OnClickListener listener)
Set the action to be displayed in this Snackbar
.
Parameters | |
---|---|
text |
CharSequence :
Text to display |
listener |
View.OnClickListener :
callback to be invoked when the action is clicked
|
Returns | |
---|---|
Snackbar |
Snackbar setActionTextColor (ColorStateList colors)
Sets the text color of the action specified in
setAction(CharSequence, View.OnClickListener)
.
Parameters | |
---|---|
colors |
ColorStateList
|
Returns | |
---|---|
Snackbar |
Snackbar setActionTextColor (int color)
Sets the text color of the action specified in
setAction(CharSequence, View.OnClickListener)
.
Parameters | |
---|---|
color |
int
|
Returns | |
---|---|
Snackbar |
Snackbar setCallback (Snackbar.Callback callback)
Set a callback to be called when this the visibility of this Snackbar
changes.
Parameters | |
---|---|
callback |
Snackbar.Callback
|
Returns | |
---|---|
Snackbar |
Snackbar setDuration (int duration)
Set how long to show the view for.
Parameters | |
---|---|
duration |
int :
either be one of the predefined lengths:
LENGTH_SHORT , LENGTH_LONG , or a custom duration
in milliseconds.
|
Returns | |
---|---|
Snackbar |
Snackbar setText (int resId)
Update the text in this Snackbar
.
Parameters | |
---|---|
resId |
int :
The new text for the Toast.
|
Returns | |
---|---|
Snackbar |
Snackbar setText (CharSequence message)
Update the text in this Snackbar
.
Parameters | |
---|---|
message |
CharSequence :
The new text for the Toast.
|
Returns | |
---|---|
Snackbar |