Read More on Telerik Blogs
April 01, 2020 Mobile, Xamarin
Get A Free Trial

Wondering how to achieve the same look for your Xamarin Forms application on both Android and iOS? Learn how to implement Material Design in your Xamarin Forms apps and make this easy.

As we know, when we are working with design in Xamarin Forms, the controls are rendered to the native controls defined by each platform. Thatโ€™s why we sometimes declare a container as simple as an Entry, and when we visualize it in Android it looks different than iOS. And that is really amazing ๐Ÿ˜! But what happens if we have a client that requires their application to look the same on both Android and iOS?

For this there is Material Design, which is a design system responsible for making our controls have the same visualization in each platform.

To be able to implement it in Xamarin, we have Xamarin.Forms Material Visual, which is used to apply the designs defined in Material Design.

โš  Important To Know

On Android:

๐Ÿ”น Material Visual requires a minimum version of 5.0 (API 21) or greater

๐Ÿ”น TargetFramework of version 9.0 (API 28)

First of Allโ€ฆ What Do I Need?

โž– Add from NuGet Package the plugin: Xamarin.Forms.Visual.Material

โž– Letโ€™s initialize Material Visual on each platform

Add the following lines after the Xamarin.Forms.Forms.Init method:

On Android: In your MainActivity.cs:

 global::Xamarin.Forms.FormsMaterial.Init(this, savedInstanceState);

On iOS: In your AppDelegate.cs:

global::Xamarin.Forms.FormsMaterial.Init();

Letโ€™s Start!

Letโ€™s Learn the Controls Supported by Material Visual

Itโ€™s important to know the controls that are actually supported by Visual. These controls are made by Material renderers, which apply the Material Design rules.

 โž– ActivityIndicator  โž– Editor 
 โž– Button  โž– Entry 
 โž– CheckBox  โž– Frame 
 โž– DatePicker  โž– Picker 
 โž– ProgressBar   โž– Slider 
 โž– Stepper  โž– TimePicker

 

Applying Material Visual

Itโ€™s so easy to use โ€“ you just have to add the Visual property to your controls.

On your XAML:

    <ContentPage Visual="Material">
         ...
    </ContentPage>

Also you can apply it in your C# file:

    ContentPage cp =  new  ContentPage();
    cp.Visual  =  VisualMarker.Material  or  VisualMarker.MatchParent  orVisualMarker.Default

Visual property gets the following values:

๐Ÿ”น Default: Render the view using the default renderer.

๐Ÿ”น Material: Render the view with the direct parents renderer.

๐Ÿ”น MatchParent: Render the view using the Material renderer.

And now letโ€™s see some examples of my favorite controls that Visual bring to us!

Thanks for reading!!! ๐Ÿ’š ๐Ÿ’•

References: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual/


About the Author

Leomaris Reyes

Leomaris Reyes is a software engineer from the Dominican Republic specializing in mobile development. She is a 7-time Microsoft MVP and actively builds mobile applications while sharing practical knowledge through technical articles and developer-focused content.

Through her work, she explains programming concepts, developer tools and real-world development practices to help developers grow in their careers.

You can follow her on Instagram and TikTok at @leomarisreyes.dev, read her articles on AskXammy, and connect with her on LinkedIn, where she shares tutorials, insights and resources for developers.

Related Posts