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 NotificationStyle for more information.
Declaration
public NotificationStyle style { get; }
Property Value
Type | Description |
---|---|
NotificationStyle |
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
Type | Description |
---|---|
Toast | The Toast instance, if no exception has occured. |
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 |
---|---|---|
VisualElement | referenceView | An arbitrary VisualElement which is currently present in the UI panel. |
string | text | The raw message or Localization dictionary key for the message to be displayed inside the Toast. |
NotificationDuration | duration | A duration enum value. |
Returns
Type | Description |
---|---|
Toast | The Toast instance, if no exception has occured. |
Remarks
The snackbar is not displayed directly, you have to call Show().
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If |
HideView(DismissType)
Called when the popup's Handler has received a k_PopupDismiss message.
Declaration
protected override void HideView(DismissType reason)
Parameters
Type | Name | Description |
---|---|---|
DismissType | 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
Type | Description |
---|---|
Toast | The Toast instance, if no exception has occured. |
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
Type | Description |
---|---|
Toast | The Toast to continuously build the element. |
SetStyle(NotificationStyle)
Set the styling used by the bar.
Declaration
public Toast SetStyle(NotificationStyle notificationStyle)
Parameters
Type | Name | Description |
---|---|---|
NotificationStyle | notificationStyle | A notification style enum value. See NotificationStyle for more information. |
Returns
Type | Description |
---|---|
Toast | The Toast to continuously build the element. |
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. |
Returns
Type | Description |
---|---|
Toast | The Toast to continuously build the element. |