<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fabricio Bertani</title>
    <description>The latest articles on DEV Community by Fabricio Bertani (@fabribertani).</description>
    <link>https://dev.to/fabribertani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F174813%2F0fadf684-50fb-4ab9-8283-794124014a59.jpg</url>
      <title>DEV Community: Fabricio Bertani</title>
      <link>https://dev.to/fabribertani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fabribertani"/>
    <language>en</language>
    <item>
      <title>Cool transition animations with Shapes in Xamarin.Forms</title>
      <dc:creator>Fabricio Bertani</dc:creator>
      <pubDate>Wed, 09 Jun 2021 14:45:12 +0000</pubDate>
      <link>https://dev.to/fabribertani/cool-transition-animations-with-shapes-in-xamarin-forms-3d25</link>
      <guid>https://dev.to/fabribertani/cool-transition-animations-with-shapes-in-xamarin-forms-3d25</guid>
      <description>&lt;p&gt;The official release of Xamarin.Forms 4.7, included for the first time the &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/"&gt;Shapes&lt;/a&gt; control, under the &lt;em&gt;experimental&lt;/em&gt; flag. Fast-forward to the present, in the actual version (&lt;em&gt;v5.0.0.2012&lt;/em&gt;), things change a lot, &lt;em&gt;Shapes&lt;/em&gt; left behind the experimental flag, and now it’s pretty stable on all supported platforms (Android, iOS, UWP, WPF and macOS).&lt;/p&gt;

&lt;p&gt;Shapes it’s a really powerful control that allow us to easily draw any shape on screen, like &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/ellipse"&gt;circles&lt;/a&gt;, &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/line"&gt;lines&lt;/a&gt;, &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/rectangle"&gt;rectangles&lt;/a&gt;, &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/polygon"&gt;polygons&lt;/a&gt; and even take values from some svg image file and paste it by using the &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path"&gt;paths&lt;/a&gt;.&lt;br&gt;
We could use this control to create graphics, good-looking backgrounds, innovative UI controls, etc., as can be seen on &lt;a href="https://devblogs.microsoft.com/xamarin/xamarin-forms-shapes-and-paths/"&gt;this great article&lt;/a&gt; by &lt;strong&gt;David Ortinau&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qfsd1wzq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/576/1%2ALkY1y9a3bOxucKUS82opMg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qfsd1wzq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/576/1%2ALkY1y9a3bOxucKUS82opMg.jpeg" alt="UI samples created with Shapes" width="576" height="820"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another really powerful tool provided by Xamarin.Forms are &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/"&gt;Animations&lt;/a&gt;, that help us to bring life to our application by using default controls or create our own custom animations.&lt;/p&gt;


&lt;h2&gt;
  
  
  Animating shapes!
&lt;/h2&gt;

&lt;p&gt;In order to make our application outstand the others, we should create something really impressive, and putting shapes with animations together seems like a good start. Also, let’s add navigation between pages into the mix.&lt;/p&gt;

&lt;p&gt;Let’s face it, Xamarin.Forms built-in transition animation it’s boring and the &lt;a href="https://github.com/GiampaoloGabba/Xamarin.Plugin.SharedTransitions"&gt;SharedTransitions&lt;/a&gt; plugin created by &lt;strong&gt;Giampaolo Gabba&lt;/strong&gt; it’s really neat, but it just contains common transitions widely used nowadays in most applications.&lt;br&gt;
We are going to create some awesome transition animations using shapes!&lt;/p&gt;

&lt;p&gt;Before starting, some considerations for this post:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Despite Shapes being available for UWP, WPF and macOS, we will stick to Android and iOS only.&lt;/li&gt;
&lt;li&gt;We are going to centralize most of the navigations on the MainPage.&lt;/li&gt;
&lt;li&gt;We will remove the original toolbar and replace it with a fake one, in order to present the animations on full screen.&lt;/li&gt;
&lt;li&gt;These are just samples, not actual production code.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Let’s get started!
&lt;/h3&gt;

&lt;p&gt;For all our pages we will use a &lt;em&gt;Grid&lt;/em&gt; control to wrap the entire page content, in order to take advantage of the overlap property.&lt;br&gt;
Also, we will set &lt;code&gt;x:Name&lt;/code&gt; to the toolbar and content to make them disappear during the transition.&lt;/p&gt;

&lt;p&gt;Here we are going to create our first shape, in this case, we want a big red arrow pointing to the right.&lt;br&gt;
Let’s use a &lt;em&gt;Path&lt;/em&gt; control. While checking the &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path-markup-syntax"&gt;markup syntax&lt;/a&gt; we can see that &lt;code&gt;Data&lt;/code&gt; field basically needs: &lt;code&gt;M&lt;/code&gt; to determine the start of the Path, next to the starting &lt;code&gt;X,Y&lt;/code&gt; points, then with &lt;code&gt;L&lt;/code&gt; we define the line and the several &lt;code&gt;X,Y&lt;/code&gt; points that it travels and finally &lt;code&gt;Z&lt;/code&gt; to signal the end of the path.&lt;br&gt;
We make it invisible and hide it on the left side of the screen.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the button click handler of our code behind, we just call an async method on the main thread that will run our &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/custom"&gt;custom animation&lt;/a&gt;.&lt;br&gt;
In the animation, we will turn the shape’s visibility on and make it move from left to right, while we fade off our toolbar and content. This whole animation will last 350 milliseconds.&lt;br&gt;
As our animation is committed synchronously, we need to add a delay a bit longer than the animation and then finally run the navigation to the next page.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Let’s check the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m1g3IgnC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2A9qWjOxglIv84HyobwZBlvw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m1g3IgnC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2A9qWjOxglIv84HyobwZBlvw.gif" alt="Left to right arrow shape transition animation" width="456" height="852"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our &lt;em&gt;ArrowNavigationPage&lt;/em&gt; will be almost the same as the &lt;em&gt;MainPage&lt;/em&gt;, but the arrow will be pointing in the opposite direction.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And code behind will be almost the same, but also add an override for the Android back button.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And this will be the result of the forward and backward navigation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0zZwfl-m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2Aw8KofpcVpOCgtTmVYi7JIg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0zZwfl-m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2Aw8KofpcVpOCgtTmVYi7JIg.gif" alt="Animation of transition from left to right and backwards" width="456" height="852"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;For our second page navigation transition, let’s create some overlapping shapes.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And let’s make it move from bottom to top&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yfqf91hg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2AlZjMFcZ5_m0RRMJjBHyloA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yfqf91hg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2AlZjMFcZ5_m0RRMJjBHyloA.gif" alt="Bottom to top arrow shape transition animation" width="456" height="852"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, for the return animation, let’s get a little more creative and create two circles using the &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/ellipse"&gt;Ellipse&lt;/a&gt;, one at the left top corner of our screen and the other at the right bottom.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We will grow a circle from the bottom right to return to its original size at the top left&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TuGKJsYU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/448/1%2AyxylmdU4hCojcv3nB5pGyg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TuGKJsYU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/448/1%2AyxylmdU4hCojcv3nB5pGyg.gif" alt="Circle shape transition animation" width="448" height="848"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Continuing with our “creative rush”, let’s create a multi-page transition animation, that’s mean an animation that starts on one screen and finish on the other one.&lt;/p&gt;

&lt;p&gt;For that reason, on the Main Page we add some shapes hidden on both sides of the screen.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the code behind, we will create an animation that closes the pane shapes we made and navigate the next page.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;On the next page, we start with the same panes shapes, but they must start closed.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the code behind, we override the &lt;code&gt;OnAppearing&lt;/code&gt; method and execute the panes open animation.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J7Pl3_0v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2AokJLlC5iJR8euR1wakV5CQ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J7Pl3_0v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/456/1%2AokJLlC5iJR8euR1wakV5CQ.gif" alt="Left and right pane shapes transition animation" width="456" height="852"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the return animation, let’s make something more interesting.&lt;/p&gt;

&lt;p&gt;Although some shapes are simple to make with paths, others won’t or would require much time to make, so we will use SVG path data for that.&lt;br&gt;
If you are lucky enough, maybe you have a UI designer on your team, you could go and ask them to make great designs that you can use.&lt;br&gt;
If not, you can use some tool like &lt;a href="https://www.figma.com/"&gt;Figma&lt;/a&gt; to create and export SVG code:&lt;/p&gt;

&lt;p&gt;Create your shape on Figma, then right-click on it, look for the &lt;em&gt;Copy/Paste&lt;/em&gt; section and select &lt;code&gt;Copy as SVG&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WuRWrfrX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/539/1%2ACV5tWR1vct4IfORKc2xAfg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WuRWrfrX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/539/1%2ACV5tWR1vct4IfORKc2xAfg.jpeg" alt="Figma contextual menu" width="539" height="733"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Paste it on your editor and take the content inside the &lt;code&gt;d&lt;/code&gt; tag&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S-vzT1zX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/700/1%2A47FHaUoQjLZ-gO3he9WmLQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S-vzT1zX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/700/1%2A47FHaUoQjLZ-gO3he9WmLQ.jpeg" alt="svg code from Figma shape" width="700" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s add all the shapes to our screen:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Remember that we need to add the same on the Main Page, but also need to say that we only want to fire that animation when return from a specific page, so we simply add a flag:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now we can add the rest of the code &lt;em&gt;PadlockTransitionAnimationShapes&lt;/em&gt; code behind for the return animation.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tVXC2oDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/450/1%2Ab--Jx67zSMv-Ia1F1KhAOA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tVXC2oDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/450/1%2Ab--Jx67zSMv-Ia1F1KhAOA.gif" alt="Padlock shape transition animation" width="450" height="848"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;For our last example, let’s stress the engine with lots of shapes and animations running on the screen. For that reason, we will make a wild pokemon appear as transition animation!&lt;/p&gt;

&lt;p&gt;For this example we add the pokemon as a png image, but you can look at some svg pokemon image to take the path 😉.&lt;/p&gt;

&lt;p&gt;These will be our shapes on the MainPage&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And the code behind’s animation:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3E_57jmM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/460/1%2AJxc-0i34HpJIQX0qBfRgMA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3E_57jmM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://miro.medium.com/max/460/1%2AJxc-0i34HpJIQX0qBfRgMA.gif" alt="Pokemon shapes transition animation" width="460" height="847"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  That’s all folks!
&lt;/h3&gt;

&lt;p&gt;As I said before, these are just samples of how we can exploit our creativity and push the boundaries of Xamarin.Forms.&lt;/p&gt;

&lt;p&gt;If this post helps you to create amazing transition animations or you want to showcase the things you’ve done, please leave a sample repo in the comments and will be added to this post later.&lt;/p&gt;

&lt;p&gt;Also, you can see a complete sample repository for this post on GitHub. 👇&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/FabriBertani"&gt;
        FabriBertani
      &lt;/a&gt; / &lt;a href="https://github.com/FabriBertani/XFShapeAnimatedTransitions"&gt;
        XFShapeAnimatedTransitions
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;XFShapeAnimatedTransitions&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;Cool transition animations with Shapes in Xamarin.Forms&lt;/p&gt;
&lt;p&gt;Sample repository created for &lt;a href="https://medium.com/geekculture/cool-transition-animations-with-shapes-in-xamarin-forms-7675e4ad0868" rel="nofollow"&gt;Cool transition animations with Shapes in Xamarin.Forms&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/FabriBertani/XFShapeAnimatedTransitions"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;Thanks for reading and keep coding! 😁&lt;/p&gt;

</description>
      <category>xamarin</category>
      <category>xamarinforms</category>
      <category>animations</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Create a Material Outlined Text Field with Xamarin.Forms</title>
      <dc:creator>Fabricio Bertani</dc:creator>
      <pubDate>Tue, 25 May 2021 15:27:03 +0000</pubDate>
      <link>https://dev.to/fabribertani/create-a-material-outlined-text-field-with-xamarin-forms-1eg1</link>
      <guid>https://dev.to/fabribertani/create-a-material-outlined-text-field-with-xamarin-forms-1eg1</guid>
      <description>&lt;p&gt;Sometime ago, the Xamarin team officially release &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual/material-visual"&gt;Material Visual&lt;/a&gt;, a feature to change the UI controls of your application in order to follow the &lt;a href="https://material.io/design"&gt;Material Design Rules &amp;amp; Guidelines&lt;/a&gt; proposed by Google. &lt;br&gt;
This is an amazing feature, as you can check on the official docs and &lt;a href="https://devblogs.microsoft.com/xamarin/visual-challenge-conquered/"&gt;other several posts&lt;/a&gt; about using it. They are built natively on each platform and have a great performance, but…(there is always a but), they just add the standard material UI elements, leaving aside other elements, like the &lt;a href="https://material.io/components/text-fields"&gt;outlined text field&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xs3b6Pqs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2AFmvKdygeyM7VEJENGd0shw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xs3b6Pqs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2AFmvKdygeyM7VEJENGd0shw.png" alt="Material outlined text field sample on the Material docs." width="778" height="349"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  For that reason, today we are going to create a material outlined textfield entirely on Xamarin.Forms!!!
&lt;/h3&gt;

&lt;p&gt;As I said before, the Material Visual feature built by Xamarin is completely native, for that reason it has better performance. We are going to have to sacrifice a bit of performance (nearly unnoticeable to the untrained eye) in order to write this control, &lt;em&gt;almost&lt;/em&gt;, without having to deal with native code on each platform.&lt;br&gt;
Before starting, let's make a list of what our control should have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rounded borders&lt;/li&gt;
&lt;li&gt;Borders should change color&lt;/li&gt;
&lt;li&gt;Placeholder animation&lt;/li&gt;
&lt;li&gt;Character counter&lt;/li&gt;
&lt;li&gt;Leading and trailing icons&lt;/li&gt;
&lt;li&gt;Interactive icons for password&lt;/li&gt;
&lt;li&gt;Helper and error texts&lt;/li&gt;
&lt;li&gt;Error icon&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In order to see what we're dealing with, we just build our app with a regular entry and a material one.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cchaLlff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2Anl9-G9toUFNHgXNeiHd-IA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cchaLlff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2Anl9-G9toUFNHgXNeiHd-IA.png" alt="Regular and material entries on Android, iOS and UWP" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's focus on the regular entry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In UWP it has a frame that we need to get rid of.&lt;/li&gt;
&lt;li&gt;In iOS also has a frame that needs to be removed.&lt;/li&gt;
&lt;li&gt;In Android, we need to remove that annoying underline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let's create some effects for it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Great! Now we need to make from our outlined text field a reusable solution, so we should create a component of it.&lt;br&gt;
We will use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Grid that contains all, because of it overlay property will help us with the placeholder animation.&lt;/li&gt;
&lt;li&gt;A Frame to wrap around the entry with rounded borders and border color.&lt;/li&gt;
&lt;li&gt;The other labels for helper, counter and error texts.&lt;/li&gt;
&lt;li&gt;Images for the icons&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Let's create our reusable component!
&lt;/h3&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And now on the code behind let's define the bindable properties, event handlers, animations  and methods.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Let's test it
&lt;/h3&gt;

&lt;p&gt;Just add the new component into a Xamarin.Forms page to see the results:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;Now let's see it running in all the 3 different supported platforms!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qbb7zYSf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2Axq51epaZl_gvJFt-KylpRw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qbb7zYSf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2Axq51epaZl_gvJFt-KylpRw.gif" alt="Our Material Outlined Entry running on Android, iOS and UWP!" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  That's all for today folks
&lt;/h3&gt;

&lt;p&gt;Hope this help you to create new cool components and explore the power of Xamarin.Forms controls.&lt;/p&gt;

&lt;p&gt;Also, you can see a complete sample repository for this post on GitHub.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/FabriBertani"&gt;
        FabriBertani
      &lt;/a&gt; / &lt;a href="https://github.com/FabriBertani/XFOutlinedMaterialEntry"&gt;
        XFOutlinedMaterialEntry
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Thanks for reading and keep coding! 😁&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; It also could works on macOS, but needs some changes and adjustments, check the sample repo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TLXtp092--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2AuNnX4aEEHb7mer2NZtsuhQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TLXtp092--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/800/1%2AuNnX4aEEHb7mer2NZtsuhQ.png" alt="Kinda running on macOS, need fixes and adjustments" width="550" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>xamarinforms</category>
      <category>materialdesign</category>
      <category>xamarin</category>
    </item>
    <item>
      <title>How to create a custom keyboard with Xamarin Forms (Android)</title>
      <dc:creator>Fabricio Bertani</dc:creator>
      <pubDate>Sun, 02 Jun 2019 18:13:32 +0000</pubDate>
      <link>https://dev.to/fabribertani/how-to-create-a-custom-keyboard-with-xamarin-forms-android-1iho</link>
      <guid>https://dev.to/fabribertani/how-to-create-a-custom-keyboard-with-xamarin-forms-android-1iho</guid>
      <description>&lt;p&gt;Some time ago a client requested a special keyboard for his application, which had to have certain conditions that the regular Android keyboard didn’t meet.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Researching&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first option that came to mind was to add a disabled &lt;code&gt;Entry&lt;/code&gt; with a &lt;code&gt;GestureRecognizer&lt;/code&gt; that displays a control with an animation to emulate the appearance of the keyboard, but quickly discard the idea as it wasn’t reusable.&lt;br&gt;
The best option was taking the native path, so I spent quite time researching, but I only found solutions that leads to create a keyboard as a service. I knew that our client wouldn’t like the idea of having to download a separate keyboard to only use it in the application and I needed a solution that should work with Xamarin Forms!&lt;br&gt;
As I had to think about its implementation in Xamarin Forms I decided that the best option was to try with a &lt;a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/" rel="noopener noreferrer"&gt;Custom Renderer&lt;/a&gt; of the Entry control since it uses &lt;em&gt;EditText&lt;/em&gt; as base for the native control and try to apply all those solutions that I had read previously in it.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Let’s get down to work!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Note: in order to correctly implement the custom keyboard we are going to need that the Xamarin Forms version to be &lt;code&gt;3.6.0.135200-pre1&lt;/code&gt; or higher because we need the &lt;a href="https://github.com/xamarin/Xamarin.Forms/blob/release-3.6.0-rc1/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs#L113" rel="noopener noreferrer"&gt;OnFocusChangeRequest&lt;/a&gt; method which is only available from this version.&lt;/p&gt;

&lt;p&gt;First we’re going to create the custom control, which will have the next bindable property:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;EnterCommand&lt;/code&gt;: typeof &lt;code&gt;ICommand&lt;/code&gt;, to bind &lt;em&gt;Enter&lt;/em&gt; key press action.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is how our custom control will be:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now we’re moving to our Android project and keep working there (later we will return to our Xamarin Forms project).&lt;br&gt;
Before we go on, ensure to have all the required Android packages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9w4xojw19e89i91rhiv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9w4xojw19e89i91rhiv.jpeg" alt="alt-text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we’re going to edit our Android &lt;code&gt;MainActivity&lt;/code&gt; to avoid that native keyboard to show up, for that we will use the &lt;code&gt;SoftInputMode.StateAlwaysHidden&lt;/code&gt; attribute&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;What are we going to do next is start to define our custom keyboard.&lt;br&gt;
Inside the &lt;em&gt;Resource/layout&lt;/em&gt; folder we are going to create an Android layout named &lt;code&gt;CustomKeyboard&lt;/code&gt; typeof &lt;code&gt;InputMethodService.Keyboard&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Firstly we set the &lt;code&gt;alignParentBottom&lt;/code&gt; property to &lt;em&gt;true&lt;/em&gt; because we want our keyboard to be visible from the bottom side of the screen.&lt;br&gt;
Secondly we set the &lt;code&gt;keyPreviewLayout&lt;/code&gt; property to &lt;em&gt;null&lt;/em&gt; because on this sample we don’t want a response layout when some key is pressed.&lt;br&gt;
As you can see in the &lt;code&gt;keyBackground&lt;/code&gt; property refers to a drawable called &lt;code&gt;keyboard_background&lt;/code&gt;, which doesn’t exist yet, so we are going to create it inside the Drawable folder as an xml file, there we are going to define a state selector for the two states our keys can have: &lt;em&gt;normal&lt;/em&gt; (without pressing) and &lt;em&gt;pressed&lt;/em&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, we are going to have to create another two xml inside the Drawable folder, in which we are going to define the &lt;em&gt;look and feel&lt;/em&gt; of our keyboard to match (or not) with our application theme.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now within the &lt;em&gt;values&lt;/em&gt; folder we will create an xml named &lt;strong&gt;ids&lt;/strong&gt; which we will need later.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Next, inside the &lt;em&gt;Resources&lt;/em&gt; folder we will create a new folder called &lt;em&gt;xml&lt;/em&gt;. Within it we will create an xml in which we will define the keys of our special keyboard.&lt;br&gt;
In our case our keyboard will be called &lt;em&gt;special_keyboard&lt;/em&gt;, it will be typeof &lt;code&gt;Keyboard&lt;/code&gt; in which we will define the horizontal and vertical size of our keys, the &lt;code&gt;horizontalGap&lt;/code&gt; and &lt;code&gt;verticalGap&lt;/code&gt; properties refer to the spacing and dimension type &lt;code&gt;%p&lt;/code&gt; (in case you’ve never seen it) is a kind of percentage relative to the parent view.&lt;br&gt;
Each row of keys will be included within sections delimited by the &lt;code&gt;&amp;lt;Row&amp;gt;&amp;lt;/Row&amp;gt;&lt;/code&gt; tags.&lt;br&gt;
Our first row will be occupied with a separating line to mark the limit of our keyboard. The Row tag will have a height of &lt;code&gt;4dp&lt;/code&gt; and we will indicate that it is at the top of our keyboard through the &lt;code&gt;rowEdgeFlags&lt;/code&gt; property. Then we will add a line as a &lt;code&gt;Key&lt;/code&gt; within the &lt;em&gt;Row&lt;/em&gt; tags that it would take the full width of the keyboard. Our separator is just another xml that we will create inside the Drawable folder:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Each &lt;em&gt;Key&lt;/em&gt; will have two strictly necessary properties: &lt;strong&gt;&lt;code&gt;codes&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;keyLabel&lt;/code&gt;&lt;/strong&gt; code will be a number that tells the OS what letter or symbol the key corresponds to. &lt;strong&gt;At this point I want to clarify something:&lt;/strong&gt; I found dozens of samples about creating customs keyboards for Android and they have used many different codes to refer to a certain symbol or key. The best list of codes that has been fulfilled most of all that I have tried is the following: &lt;a href="http://www.temblast.com/ref/akeyscode.htm" rel="noopener noreferrer"&gt;Android Keycodes&lt;/a&gt;. You can also see the &lt;a href="https://developer.android.com/reference/android/view/KeyEvent" rel="noopener noreferrer"&gt;official Android&lt;/a&gt; docs or even the &lt;a href="https://developer.android.com/reference/android/view/KeyEvent" rel="noopener noreferrer"&gt;Xamarin Android&lt;/a&gt; but none of them has worked with accuracy.&lt;br&gt;
&lt;strong&gt;keyLabel&lt;/strong&gt; is the string that is going to be shown in our key, it is very important to put this property even if we don’t want to show any text in our key (in that case it would be &lt;code&gt;keyLabel=""&lt;/code&gt;).&lt;br&gt;
For style decision, at the beginning and at the end of each row, I add a Key with &lt;em&gt;code&lt;/em&gt; equal to 0 (so you don’t have any action), the width also of 0 and a spacing of &lt;code&gt;2%p&lt;/code&gt;, these keys will also carry the &lt;code&gt;keyEdgeFlags&lt;/code&gt; property with the &lt;code&gt;left&lt;/code&gt; or &lt;code&gt;right&lt;/code&gt; values as appropriate.&lt;br&gt;
Here our full keyboard:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally before starting to work in our renderer, we will create another folder within Resources, called &lt;em&gt;anim&lt;/em&gt; with an xml that we are going to call &lt;code&gt;slide_in_bottom&lt;/code&gt; this will be the animation with which our keyboard will appear on the screen.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now we will create a new folder on our Android project, named &lt;em&gt;Renderers&lt;/em&gt; and there we will create our renderer which we will call &lt;code&gt;EntryWithCustomKeyboardRenderer&lt;/code&gt; which will extend from &lt;code&gt;EntryRenderer&lt;/code&gt; and implement the interface &lt;code&gt;IOnKeyboardActionListener&lt;/code&gt;. Also within our custom renderer we will create a private class called &lt;code&gt;NullListener&lt;/code&gt; which is going to extend from &lt;code&gt;Java.Lang.Object&lt;/code&gt; and implement the interface &lt;code&gt;IOnKeyboardActionListener&lt;/code&gt; which we are going to use in our renderer to avoid null exceptions.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, we return to our Xamarin Forms project and implement our special keyboard.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And in our code behind we implement the &lt;code&gt;EnterCommand&lt;/code&gt; that we created previously, for the action that we want to happen when we press the &lt;em&gt;Enter&lt;/em&gt; key of our custom keyboard.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here’s the final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AuQOUSV87TkUnp1HLkunf9A.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AuQOUSV87TkUnp1HLkunf9A.gif" alt="alt-text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the complete sample repository on GitHub&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/FabriBertani" rel="noopener noreferrer"&gt;
        FabriBertani
      &lt;/a&gt; / &lt;a href="https://github.com/FabriBertani/CustomKeyboardXamarinForms" rel="noopener noreferrer"&gt;
        CustomKeyboardXamarinForms
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      How to create a custom keyboard with Xamrain Forms (Android)
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;CustomKeyboardXamarinForms&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;How to create a custom keyboard with Xamrain Forms (Android)&lt;/p&gt;
&lt;p&gt;Sample repository created for &lt;a href="https://medium.com/swlh/how-to-create-a-custom-keyboard-with-xamarin-forms-android-4fa3b83dad1d" rel="nofollow noopener noreferrer"&gt;How to create a custom keyboard with Xamarin Forms (Android)&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/FabriBertani/CustomKeyboardXamarinForms" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;In the next post we will see how to make a complex custom keyboard!&lt;/p&gt;

&lt;p&gt;Thanks for reading 😁&lt;/p&gt;

</description>
      <category>android</category>
      <category>xamarin</category>
      <category>keyboard</category>
      <category>apps</category>
    </item>
  </channel>
</rss>
