Class Toast
A toast is a view containing a quick little message for the user.
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public sealed class Toast : PopupNotification<Toast>
Properties
icon
The icon used inside the Toast as leading UI element.
Declaration
public string icon { get; }
Property Value
Type | Description |
---|---|
string |
style
Returns the styling used by the bar. See Notification
Declaration
public NotificationStyle style { get; }
Property Value
Type | Description |
---|---|
Notification |
text
Returns the raw message or Localization dictionary key used by the bar.
Declaration
public string text { get; }
Property Value
Type | Description |
---|---|
string |
Methods
AddAction(int, string, Action<Toast>, bool)
Add an Action to display in the Toast bar.
Declaration
public Toast AddAction(int actionId, string message, Action<Toast> callback, bool autoDismiss = true)
Parameters
Type | Name | Description |
---|---|---|
int | actionId | The Action ID, which is a unique identifier for your action. |
string | message | The raw message or Localization dictionary key for the action to be displayed. |
Action<Toast> | callback | The callback which will be called when the action is triggered. |
bool | autoDismiss | Whether the toast should be dismissed automatically after the action is triggered. |
Returns
Build(VisualElement, string, NotificationDuration)
Build and return a Toast UI element.
The method will find the best suitable parent view which will contain the Toast element.
Declaration
public static Toast Build(VisualElement referenceView, string text, NotificationDuration duration)
Parameters
Type | Name | Description |
---|---|---|
Visual |
referenceView | An arbitrary Visual |
string | text | The raw message or Localization dictionary key for the message to be displayed inside the Toast. |
Notification |
duration | A duration enum value. |
Returns
Remarks
The snackbar is not displayed directly, you have to call Show().
Exceptions
Type | Condition |
---|---|
Argument |
If |
HideView(DismissType)
Called when it is time to hide the popup.
Declaration
protected override void HideView(DismissType reason)
Parameters
Type | Name | Description |
---|---|---|
Dismiss |
reason | The reason why the popup should be dismissed. |
Overrides
InvokeShownEventHandlers()
Called when the popup has become visible. This method will invoke any handlers attached to the shown event.
Declaration
protected override void InvokeShownEventHandlers()
Overrides
RemoveAction(int)
Remove an already existing action.
Declaration
public Toast RemoveAction(int actionId)
Parameters
Type | Name | Description |
---|---|---|
int | actionId | The Action ID. |
Returns
SetIcon(string)
Set a new value for the icon property.
Declaration
public Toast SetIcon(string iconName)
Parameters
Type | Name | Description |
---|---|---|
string | iconName | The name of the icon. |
Returns
SetStyle(NotificationStyle)
Set the styling used by the bar.
Declaration
public Toast SetStyle(NotificationStyle notificationStyle)
Parameters
Type | Name | Description |
---|---|---|
Notification |
notificationStyle | A notification style enum value. See Notification |
Returns
SetText(string)
Update the text in the Toast.
Declaration
public Toast SetText(string txt)
Parameters
Type | Name | Description |
---|---|---|
string | txt | The raw message or Localization dictionary key for the message to be displayed. |