What's new for textual content in Android Q

Posted by Florina Muntenescu, Android Growth Advocate

Textual content show is a crucial job in most purposes. Due to this fact, in Android Q, we proceed to introduce new options to satisfy your wants and enhance efficiency. We've disabled hyphenation by default, enabled font creation with the assistance of a number of fonts or font households, uncovered the listing of fonts put in on the gadget, and enhanced a number of the model APIs. most used textual content.

Hyphenation is disabled by default in Android Q and AppCompat v1.1.zero

Our efficiency exams have proven that when hyphenation is enabled, as much as 70% of the time spent on textual content measurement is dedicated to hyphenation.

Hyphenation takes as much as 70% of the time wanted to measure the textual content

Since hyphenation is usually not mandatory for all TextViews in an software and due to its influence on efficiency, we determined to disable the default hyphenation in Android Q and AppCompat v1.1.zero . If you wish to use hyphenation, you have to manually allow it in your software by setting the hyphenation frequency to regular. You possibly can outline this in a number of methods:

As a TextAppearance attribute in types.xml:

As a TextView attribute:

Straight within the code:

textView.hyphenationFrequency = Format.HYPHENATION_FREQUENCY_NORMAL

To study extra about how hyphenation works from this speak, on Android Dev Summit 2018.

Utilizing A number of Customized Fonts within the Identical TextView

Contemplate a button that mixes a customized font (Lato on this instance) with an icon kind font:

Button with icon and Latin fonts

The Button class solely accepts one occasion of a personality to set on the textual content. Earlier than Android Q, you’ll be able to create a font utilizing a single font household. Android Q permits the creation of a font from a number of font households with a brand new API, Typeface.CustomFallbackBuilder, permitting so as to add as much as 64 font households by police.

Our icon font instance may be applied like this:

button.typeface = Typeface.CustomFallbackBuilder (
// add latin font
FontFamily.Builder (
Font.Builder (property, "lato.ttf"). Construct ()
).to construct()
) .addCustomFallback (
// add the font of the icon
FontFamily.Builder (
Font.Builder (property, "icon_font.ttf"). Construct ()
).to construct()
).to construct()

When creating the font household, guarantee that doesn’t place fonts belonging to completely different households in the identical font household object or in the identical model, in the identical font household . For instance, inserting Lato, Kosugi, and Materials in the identical font household creates an invalid configuration, as does inserting two daring fonts in the identical font household.

To set the overall font household (serif, sans-serif, or monospace) to make use of when textual content is rendered utilizing system fonts, use the setSystemFallback () technique to set the system failover coverage:

Typeface.CustomFallbackBuilder (
FontFamily.Builder (

).to construct()
) .setSystemFallback ("sans-serif")
.to construct()

Updates from the textual content model API

Android Q brings a number of updates to completely different textual content model APIs:

Improved help for variable fonts

TextAppearance now helps the fontVariationSettings attribute:

The fontVariationSettings attribute may be set straight on TextView in Android Q and in AppCompatTextView:

Enhanced scope API

TextAppearanceSpan now helps character varieties, shadow settings, FontFeatureSettings, and FontVariationSettings.

The LineBackgroundSpan and LineHeightSpan interfaces now have customary implementations: LineBackgroundSpan.Normal and LineHeightSpan.Normal.

Fonts of the entry system

With over 100 languages ​​supported by Android and completely different fonts that help completely different character units, it's not trivial to know which system font can render a given character. Purposes that render their very own textual content, akin to video games, doc viewers, or browsers, want this data. In Android Q, you’ll be able to recuperate the system font help for a string utilizing the NDK FontMatcher API.

System Fonts That Can Return This Textual content

Contemplate the search string above. The FontMatcher API returns us the thing and the size of the font. An instance of a simplified pseudocode appears like this:

// font = NotoSansCJK-Common.ttc
// size = 2
auto [font, length] = AFontMatcher_match ("す く a.okay.a. の");

// font = Roboto-Common.ttf
// size = eight
auto [font, length] = AFontMatcher_match ("a.okay.a. の な");

// font = NotoSansCJK-Common.ttc
// size = 2
auto [font, length] = AFontMatcher_match ("な");

The FontMatcher API by no means returns nullptr:

If no font helps the given string, a font for Tofu (), the lacking glyph image, is returned.

If no actual model is supported, a font containing the closest and most comparable model is returned.

If you need to get all of the system fonts out there you are able to do it with a brand new font enumeration API. In Java, you should use SystemFonts.getAvailableFonts, or within the NDK, you should use ASystemFontIterator. The outcomes of font enumeration are solely modified by a system replace. You have to cache them.

Font Updates

New Police of Myanmar

Android has added a brand new Myanmar font to Android Q, suitable with Unicode and able to rendering Unicode and non-Unicode Burmese (extra generally generally known as Zawgyi) codecs proper out of the field. Because of this from Android Q, Android makes it simple for customers to modify to Unicode: a person can now use a Unicode font to learn Unicode and non-Unicode textual content for the primary time. Android has additionally added new necessities to the CDD of the Android ecosystem, which takes a stronger place by requiring Unicode, together with a brand new subtag "Qaag" that builders ought to use as a locale designating Burmese customers not -unicode. All of those adjustments ought to make life simpler for builders in the long term, as lowering ecosystem fragmentation facilitates the event of our 50 million customers in Myanmar.

New emojis

New emoticons in Android Q

Say good day to your new emoji associates! The most recent replace contains various emojis centered on folks with disabilities, 59 gender-inclusive patterns, multiracial couples, in addition to some cute animals and home goods. Try the most recent Gboard information in your Android Q gadget of your selection.

Textual content performs an necessary position within the overwhelming majority of purposes. So we proceed to spend money on bettering the options and efficiency of the textual content API. Study extra in regards to the new Android Q APIs and greatest practices for utilizing textual content in our Google I / O 2019 speak: