I'm building a Xamarin CrossPlatform App!
I wanted to add a floating action button at the bottom right corner of the app page just like this
Here is my XAML code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Last_MSPL.Views.HomePage">
<ListView x:Name="Demolist" ItemSelected="OnItemSelected" BackgroundColor="AliceBlue">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem x:Name="OnMore" Clicked="OnMore_Clicked" CommandParameter="{Binding .}"
Text="More" />
<MenuItem x:Name="OnDelete" Clicked="OnDelete_Clicked" CommandParameter="{Binding .}"
Text="Delete" IsDestructive="True" />
</ViewCell.ContextActions>
<StackLayout>
<StackLayout Padding="15,0">
<Label Text="{Binding employee_name}" FontAttributes="bold" x:Name="en"/>
<Label Text="{Binding employee_age}"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
How can I do this using XAML? Help me through this, Thanks!
the quickest way:
Don't forget to add the "add.png" icon to your resources
**
If you want a solution thats simple and without downloading libraries or anything try this:
**
In your xaml you can use a normal button with rounded corners. Just make sure both width and height are the same. To have it float use a absolute layout and put the button on the bottom. I pasted mine and its style entry from my app.xml resource dictionary.
(Ive used both the james montenago packages and the suave controls. The first doesn't work on iOS and the latter doesn't show images on Android. This solution works on both iOS and Android.)
XAML:
Resource dictionary entry:
(When height and width are both 50.)
You can use for Android, Floating Action Button (https://developer.android.com/guide/topics/ui/floating-action-button) if you want to use native control, and a custom board for iOS. Otherwise you can add to your Xamarin.Forms page a RelativeLayout container and specity constraints where you want. Something like this:
You can change Button with any other control and you can correct position just changing the value of "Constant=-60"
You can use an
ImageButton
(Xamarin.Forms v3.4+)Create your image with a transparent background in your favorite editor and then assign it a location on the Page.
Example using an AbsoluteLayout, just place your "FAB" as the last element so that its Z-order is highest and it will "float" above the rest of the content.
Output:
Using Floating action button in
Xamarin Forms
is easier than you might think, All you need is a little bit of AbsoluteLayout and anImageButton
that can respond to your clicks and voila! your FAB is readyAdd a custom
ImageButton
Control something like below:Once you have that up and running in a layout whose parent-most is an AbsoluteLayout add the ImageButton like below:
Where customControls is the namespace where you added your ImageButton custom control.
For better understanding check where I referenced it from which can be found here
Good luck
Revert in case you have any sort of query.