Class FloatingActionButton
A circular button that promotes a primary action in the application.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class FloatingActionButton : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IPressable
Remarks
The Floating Action Button (FAB) represents the primary action in an application. It appears on top of the main content and stays fixed in a position (usually bottom right) as a circular button with elevation (shadow).
FABs are used for positive actions like Create, Favorite, Share, or Start. The action should be contextual to the screen's main content.
Only use one FAB per screen to represent the most important action. Multiple FABs can cause confusion about which action is primary.
The component supports different sizes, elevation levels, and can be styled with an accent color to make it more prominent.
Examples
Basic FAB with default settings. Creates a medium-sized FAB with the add icon.
<FAB>
<Icon name="add" />
</FAB>
Accent FAB with custom elevation. Creates an accent-colored FAB with higher elevation.
<FAB accent="true" elevation="16">
<Icon name="favorite" />
</FAB>
Code example showing FAB creation and event handling. Creating and configuring FAB in C# code.
var fab = new FloatingActionButton(() => {
Debug.Log("FAB clicked!");
});
fab.size = Size.L;
fab.accent = true;
fab.Add(new Icon { name = "add" });
parentElement.Add(fab);
Constructors
FloatingActionButton()
Default constructor.
Declaration
public FloatingActionButton()
FloatingActionButton(Action)
Default constructor.
Declaration
public FloatingActionButton(Action clickAction)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | clickAction | The action to perform when the button is clicked. |
Fields
accentUssClassName
The Floating Action Button's accent USS class name.
Declaration
public const string accentUssClassName = "appui-fab--accent"
Field Value
| Type | Description |
|---|---|
| string |
elevationUssClassName
The Floating Action Button's elevation USS class name.
Declaration
public const string elevationUssClassName = "appui-elevation-"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Floating Action Button's size USS class name.
Declaration
public const string sizeUssClassName = "appui-fab--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Floating Action Button's USS class name.
Declaration
public const string ussClassName = "appui-fab"
Field Value
| Type | Description |
|---|---|
| string |
Properties
accent
The accent variant of this element.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool accent { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
clickable
The clickable manipulator used by this button.
Declaration
[CreateProperty]
public Pressable clickable { get; }
Property Value
| Type | Description |
|---|---|
| Pressable |
contentContainer
The content container of this element.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
elevation
The elevation of this element.
Declaration
[CreateProperty]
[UxmlAttribute]
public int elevation { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
size
The size of this element.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
Events
clicked
Event fired when the button is clicked.
Declaration
public event Action clicked
Event Type
| Type | Description |
|---|---|
| Action |