Avenir Font For Android

-->Next

By default, Xamarin.Forms uses a system font defined by each platform. However, controls that display text define properties that you can use to change this font:

If the font file has a TTF or OTF extension, you can physically copy it over to your PC and it will work there. However, that wouldn't be legal. The font family Avenir is licensed just like your operating system or your apps. Adobe Fonts partners with the world’s leading type foundries to bring thousands of beautiful fonts to designers every day. No need to worry about licensing, and you can use fonts from Adobe Fonts on the web or in desktop applications.

  • FontAttributes, of type FontAttributes, which is an enumeration with three members: None, Bold, and Italic. The default value of this property is None.
  • FontSize, of type double.
  • FontFamily, of type string.
Avenir Font For Android

These properties are backed by BindableProperty objects, which means that they can be targets of data bindings, and styled.

Set font attributes

Controls that display text can set the FontAttributes property to specify font attributes:

The equivalent C# code is:

Set the font size

Controls that display text can set the FontSize property to specify the font size. The FontSize property can be set to a double value directly, or by a NamedSize enumeration value:

The equivalent C# code is:

Alternatively, the Device.GetNamedSize method has an override that specifies the second argument as an Element:

Note

The FontSize value, when specified as a double, is measured in device-independent units. For more information, see Units of Measurement.

For more information about named font sizes, see Understand named font sizes.

Set the font family

Controls that display text can set the FontFamily property to a font family name, such as 'Times Roman'. However, this will only work if that font family is supported on the particular platform.

There are a number of techniques that can be used to attempt to derive the fonts that are available on a platform. However, the presence of a TTF (True Type Format) font file does not necessarily imply a font family, and TTFs are often included that are not intended for use in applications. In addition, the fonts installed on a platform can change with platform version. Therefore, the most reliable approach for specifying a font family is to use a custom font.

Custom fonts can be added to your Xamarin.Forms shared project and consumed by platform projects without any additional work. The process for accomplishing this is as follows:

  1. Add the font to your Xamarin.Forms shared project as an embedded resource (Build Action: EmbeddedResource).
  2. Register the font file with the assembly, in a file such as AssemblyInfo.cs, using the ExportFont attribute. An optional alias can also be specified.

The following example shows the Lobster-Regular font being registered with the assembly, along with an alias:

Note

The font can reside in any folder in the shared project, without having to specify the folder name when registering the font with the assembly.

On Windows, the font file name and font name may be different. To discover the font name on Windows, right-click the .ttf file and select Preview. The font name can then be determined from the preview window.

The font can then be consumed on each platform by referencing its name, without the file extension:

Alternatively, it can be consumed on each platform by referencing its alias:

The equivalent C# code is:

Avenir Font For Android

The following screenshots show the custom font:

Download Avenir Next Font OTF, TTF

Important

For release builds on Windows, ensure the assembly containing the custom font is passed as an argument in the Forms.Init method call. For more information, see Troubleshooting.

Set font properties per platform

The OnPlatform and On classes can be used in XAML to set font properties per platform. The example below sets different font families and sizes on each platform:

The Device.RuntimePlatform property can be used in code to set font properties per platform

For more information about providing platform-specific values, see Provide platform-specific values. For information about the OnPlatform markup extension, see OnPlatform markup extension.

Understand named font sizes

Xamarin.Forms defines fields in the NamedSize enumeration that represent specific font sizes. The following table shows the NamedSize members, and their default sizes on iOS, Android, and the Universal Windows Platform (UWP):

MemberiOSAndroidUWP
Default171414
Micro121015.667
Small141418.667
Medium171722.667
Large222232
Body171614
Header179646
Title282424
Subtitle221620
Caption121212

The size values are measured in device-independent units. For more information, see Units of Measurement.

Note

On iOS and Android, named font sizes will autoscale based on operating system accessibility options. This behavior can be disabled on iOS with a platform-specific. For more information, see Accessibility Scaling for Named Font Sizes on iOS.

For

Display font icons

Font icons can be displayed by Xamarin.Forms applications by specifying the font icon data in a FontImageSource object. This class, which derives from the ImageSource class, has the following properties:

Avenir Font For Android Phones

  • Glyph – the unicode character value of the font icon, specified as a string.
  • Size – a double value that indicates the size, in device-independent units, of the rendered font icon. The default value is 30. In addition, this property can be set to a named font size.
  • FontFamily – a string representing the font family to which the font icon belongs.
  • Color – an optional Color value to be used when displaying the font icon.

See Full List On Fontsnetwork.com

This data is used to create a PNG, which can be displayed by any view that can display an ImageSource. This approach permits font icons, such as emojis, to be displayed by multiple views, as opposed to limiting font icon display to a single text presenting view, such as a Label.

Avenir Font For Android App

Important

Font icons can only currently be specified by their unicode character representation.

The following XAML example has a single font icon being displayed by an Image view:

This code displays an XBox icon, from the Ionicons font family, in an Image view. Note that while the unicode character for this icon is uf30c, it has to be escaped in XAML and so becomes . The equivalent C# code is:

Avenir Next

The following screenshots, from the Bindable Layouts sample, show several font icons being displayed by a bindable layout:

See Full List On Designyourway.net

Related links

Comments are closed.