belongs to Maven artifact com.android.support:design:27.1.0
Snackbar
public
final
class
Snackbar
extends BaseTransientBottomBar<Snackbar>
java.lang.Object | ||
↳ | android.support.design.widget.BaseTransientBottomBar<android.support.design.widget.Snackbar> | |
↳ | 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 addCallback(BaseCallback)
.
Summary
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. |
Inherited constants |
---|
From
class
android.support.design.widget.BaseTransientBottomBar
|
Public methods | |
---|---|
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)
This method was deprecated
in API level 26.1.0.
Use |
Snackbar
|
setText(CharSequence message)
Update the text in this |
Snackbar
|
setText(int resId)
Update the text in this |
Inherited methods | |
---|---|
From
class
android.support.design.widget.BaseTransientBottomBar
| |
From
class
java.lang.Object
|
Constants
LENGTH_INDEFINITE
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)
LENGTH_LONG
int LENGTH_LONG
Show the Snackbar for a long period of time.
See also:
Constant Value: 0 (0x00000000)
LENGTH_SHORT
int LENGTH_SHORT
Show the Snackbar for a short period of time.
See also:
Constant Value: -1 (0xffffffff)
Public methods
make
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 |
make
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 |
setAction
Snackbar setAction (int resId, View.OnClickListener listener)
Set the action to be displayed in this BaseTransientBottomBar
.
Parameters | |
---|---|
resId |
int : String resource to display for the action |
listener |
View.OnClickListener : callback to be invoked when the action is clicked
|
Returns | |
---|---|
Snackbar |
setAction
Snackbar setAction (CharSequence text, View.OnClickListener listener)
Set the action to be displayed in this BaseTransientBottomBar
.
Parameters | |
---|---|
text |
CharSequence : Text to display for the action |
listener |
View.OnClickListener : callback to be invoked when the action is clicked
|
Returns | |
---|---|
Snackbar |
setActionTextColor
Snackbar setActionTextColor (ColorStateList colors)
Sets the text color of the action specified in
setAction(CharSequence, View.OnClickListener)
.
Parameters | |
---|---|
colors |
ColorStateList |
Returns | |
---|---|
Snackbar |
setActionTextColor
Snackbar setActionTextColor (int color)
Sets the text color of the action specified in
setAction(CharSequence, View.OnClickListener)
.
Parameters | |
---|---|
color |
int |
Returns | |
---|---|
Snackbar |
setCallback
Snackbar setCallback (Snackbar.Callback callback)
This method was deprecated
in API level 26.1.0.
Use addCallback(BaseCallback)
Set a callback to be called when this the visibility of this Snackbar
changes. Note that this method is deprecated
and you should use addCallback(BaseCallback)
to add a callback and
removeCallback(BaseCallback)
to remove a registered callback.
Parameters | |
---|---|
callback |
Snackbar.Callback : Callback to notify when transient bottom bar events occur. |
Returns | |
---|---|
Snackbar |
setText
Snackbar setText (CharSequence message)
Update the text in this Snackbar
.
Parameters | |
---|---|
message |
CharSequence : The new text for this BaseTransientBottomBar .
|
Returns | |
---|---|
Snackbar |
setText
Snackbar setText (int resId)
Update the text in this Snackbar
.
Parameters | |
---|---|
resId |
int : The new text for this BaseTransientBottomBar .
|
Returns | |
---|---|
Snackbar |
Annotations
Interfaces
- AppBarLayout.OnOffsetChangedListener
- BaseTransientBottomBar.ContentViewCallback
- BottomNavigationView.OnNavigationItemReselectedListener
- BottomNavigationView.OnNavigationItemSelectedListener
- CoordinatorLayout.AttachedBehavior
- NavigationView.OnNavigationItemSelectedListener
- SwipeDismissBehavior.OnDismissListener
- TabLayout.OnTabSelectedListener
Classes
- AppBarLayout
- AppBarLayout.Behavior
- AppBarLayout.Behavior.DragCallback
- AppBarLayout.Behavior.SavedState
- AppBarLayout.LayoutParams
- AppBarLayout.ScrollingViewBehavior
- BaseTransientBottomBar
- BaseTransientBottomBar.BaseCallback
- BottomNavigationView
- BottomSheetBehavior
- BottomSheetBehavior.BottomSheetCallback
- BottomSheetBehavior.SavedState
- BottomSheetDialog
- BottomSheetDialogFragment
- CollapsingToolbarLayout
- CollapsingToolbarLayout.LayoutParams
- CoordinatorLayout
- CoordinatorLayout.Behavior
- CoordinatorLayout.LayoutParams
- CoordinatorLayout.SavedState
- FloatingActionButton
- FloatingActionButton.Behavior
- FloatingActionButton.OnVisibilityChangedListener
- NavigationView
- NavigationView.SavedState
- Snackbar
- Snackbar.Callback
- SwipeDismissBehavior
- TabItem
- TabLayout
- TabLayout.Tab
- TabLayout.TabLayoutOnPageChangeListener
- TabLayout.ViewPagerOnTabSelectedListener
- TextInputEditText
- TextInputLayout
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.