What's new for text in Android Q.

What's new for text in Android Q.

Posted by Florina Muntenescu, Android Developer Advocate

Displaying is an important task in most apps, so in Android Q we are continuing to introduce new features to support your needs and improve performance. We disabled hyphenation by default, enabled creating a typeface using multiple fonts or font families, exposed the list of fonts installed on the device, and improved some of the most-used text styling APIs.

Hyphenation is off by default in Android Q and AppCompat v1.1.0

Our performance tests showed that when hyphenation is enabled, up to 70% of the time spent reading on hyphenation.

pie chart showing StaticLayout: Hyphenation takes up 70% of the time spent reading text, 30% Other text

Hyphenation takes up to 70% of the time spent reading text

Given that hyphenation is often not needed for all TextViews in an app, and because of the impact on performance, we decided to turn off hyphenation by default in Android Q and AppCompat v1.1.0. If you want to use hyphenation, you need to turn it on in your app by setting the hyphenation frequency to normal. You can set this in multiple ways:

As a TextAppearance attributes in styles.xml:


As a text View attribute:


Directly in code:

        textView.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NORMAL  

Find out more about how hyphenation works from this talk at Android Dev Summit 2018.

Use multiple custom fonts in the same TextView

Consider a button which mixes a custom font (Lato in this example) with an icon font:

Secure Checkout Button with lock icon, icon and latin fonts

Button with icon and latin fonts

The button class accepts only a single instance of a typeface to be set on the text. Pre-Android Q, you can create a Typeface using a single font family. Android Q enables the creation of a typeface from multiple font families with a new API, Typeface.CustomFallbackBuilder, that allows adding up 64 font families via typeface.

Our icon font example can be implemented like this:

        button.typeface = Typeface.CustomFallbackBuilder (// add the Latin font FontFamily.Builder (Font.Builder (assets, "lato.ttf"). build ()) .build ()) .addCustomFallback (// add the icon font FontFamily .Builder (Font.Builder (assets, "icon_font.ttf"). Build ()) .build ()) .build ()  

When creating the font family, make sure you do not put fonts that belong to different families in the same font family object nor the same style fonts into the same font family. For example, putting Lato, Kosugi, and material into the same font family creates an invalid configuration.

To define the general font family (serif, sans-serif, or monospace) setSystemFallback () method to set the system fallback font:

        Typeface.CustomFallbackBuilder (FontFamily.Builder (...) .build ()) .setSystemFallback ("sans-serif") .build ()  

Text styling API updates

Android Q brings several updates to different text styling APIs:

Improved support for variable fonts

TextAppearance now supports the font variation settings attribute:


The font variation settings attribute can be set directly on the text View in Android Q and in AppCompatTextView:


Improved spans APIs

TextAppearanceSpan now supports typeface, shadow settings, font feature settings and font variation settings,

Line Background tension and LineHeight tension interfaces now have standard implementations: LineBackgroundSpan.Standard and LineHeightSpan.Standard,

Access system fonts

With more than 100 languages ​​supported by Android, and with different font supporting different character sets, knowing which system can render a given character is not trivial. Apps doing their own text rendering such as games, document viewers, or browsers need this information. In Android Q, you can retrieve the supported system font for a string with the Font Matcher NDK API.

System fonts that can render this text

System fonts that can render this text

Let's consider the above search string Font Matcher API returns us the font object and length. A simplified pseudocode example looks like this:

        // font = NotoSansCJK-Regular.ttc // length = 2 auto[font, length] = AFontMatcher_match ("た す く a.k.a. の な"); // font = Roboto-Regular.ttf // length = 8 auto[font, length] = AFontMatcher_match ("a.k.a. の な"); // font = NotoSansCJK-Regular.ttc // length = 2 auto[font, length] = AFontMatcher_match ("の な");  

The Font Matcher API never returns nullptr:

  • If no font supports the given string, a font for tofu (󟿽), the missing glyph symbol, is returned.
  • If no exact style is supported, a font with the closest, most similar style is returned.

If you want to get all available system fonts, you can use this with a new font enumeration API. In Java, you can use SystemFonts.getAvailableFonts, or in the NDK, you can use ASystemFontIterator, The results of the font enumeration are only changed by a system update, so you should cache them.

Font updates

New Myanmar font

Unicode and non-Unicode Burmese (commonly known as Zawgyi), right out of the box. This means starting in Android Q, Android makes it easier for users to switch to Unicode: a user can now use a Unicode font to read Unicode and non-Unicode text for the first time. Android also requires Unicode, including a new subtag “Qaag” which OEMs should use as a non-Unicode Burmese designating locale. All of these changes should make it easier to develop our 50M users in Myanmar.

New emojis

New emojis in Android Q.

New emojis in Android Q.

Say hello to your new emoji friends! The latest update includes a number of disability-focused emojis, 59 gender-inclusive designs, multi-racial couples, as well as a few cute pets and household objects. See the latest and greatest on Gboard on your Android Q device of choice.

API plays and performance. Text plays an important role in a vast majority of apps. Learn more about the new APIs in Android Q along with best practices when working with text on our Google I / O 2019 talk:

#Google #Android #Smartphones #OS #News @ndrdnws #ndrdnws #AndroidNews

Leave a Reply

Your email address will not be published. Required fields are marked *

Craft space and home office in a closet – The Crazy Craft Lady featured on Remod…