Dynamic font sizes ? so the size of text is able to change according to device/ size of screen?

LouissLouiss Member ✭✭

nexus 4

nexus 10


  • Dinesh_OfficialDinesh_Official Member ✭✭✭
    edited February 5

    @Louiss ,

    var dp = Android.App.Application.Context.Resources.DisplayMetrics.Density;

    Xamarin Essentials:

    var dp = Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density;

    If you have definite Size, use the dependency which shared above to get the device density which vary device to device and multiply it with your value.

    label.FontSize = ConstantValue*dp

    Otherwise, if you are using Xamarin.Essentials nuget in your application, refer the above code example.

    If you are aware of font type, you can choose a required from the NamedSize where framework itself handle everything.

    For Code behind refer the below code snippet.

    label.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label));

    For XAML refer below image.

    Also, refer the below documentation.


Sign In or Register to comment.