Posts

Showing posts with the label XAMARIN FORMS

[Xamarin Forms] Button text alignment issue in Android

Image
Recently, I had to deal with custom Buttons in my Android application. So I designed custom renderers to render it. Unfortunately, I encountered a strange behavior with the text alignment of my buttons. This happens when the button changes of state : - Originally the button's text is centered - When you click it, the text moves to the left See images below:   Before / after the button click After investigating, I found a solution to my problem. In my Android custom button renderer, I had to overwrite a specific method:  ChildDrawableStateChanged public class ExtButtonRenderer : ViewRenderer<Extbutton, global::android.widget.button> { ... public override void ChildDrawableStateChanged(Android.Views.View child) { base.ChildDrawableStateChanged(child); if (Control != null) Control.Text = Control.Text; } ... } That's all ! Related links: Custom renderers: http://developer.xamarin.com/guides

[Xamarin Forms] Embed custom fonts in your apps

Image
Recently I had some difficulties to embed custom fonts in my applications. Specially with the iOS application that was crashing with no message (while it was working for the Android version). In fact, it was a font issue. So in this post I will show you some tips to embed quickly custom fonts in both your Android & iOS apps. 1- Select your fonts The first step is to get some cool fonts you want to use. You'll maybe use (free) fonts from various websites like: www.1001freefonts.com www.dafont.com 2- Set font files properties In your solution, include your fonts files: iOS:  Create a subfolder (in the the 'Resources' directory) where to embed the fonts Build Action = BundleResource & "Copy Always" Android : Create a subfolder in the 'Assets' directory where to embed the fonts: Build Action = "AndroidAsset" & "Copy Always" 3- iOS application: edit your plist file With iOS you need to specify the e

[TIP] "Dispatcher.BeginInvoke()" in Xamarin.Forms

In traditional WP8 apps, when you want to update a visual element but you are not in the UI thread, you have to use the dispatcher like this: Deployment.Current.Dispatcher.BeginInvoke( /* my custom task */); In Xamarin.Forms, you have to use the Device 's object static method: Device.BeginInvokeOnMainThread(() => { // your code on UI thread here... });