Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Text samples

This sample demonstrates several text-related features in Android.

Apps can create a font resource XML and declare it in their 'AndroidManifest.xml' to let the system prefetch the font. The font family can be used with android:fontFamily in layout XMLs.

Alternatively, apps can use FontsContractCompat to download fonts dynamically.

Read Use Downloadable Fonts for the detail.

buildSpannedString in the core-ktx library is useful for quickly building a rich text.

LinkifyCompat is useful for creating links in TextViews. The API supports email addresses, phone numbers, and web URLs out of the box, and you can also use regular expressions to create a custom link pattern.

Automatic hyphenation is available for a number of languages including English.

Android 6.0 Marshmallow (API level 23) introduced the android:hyphenationFrequency attribute to apply automatic hyphenation to a TextView.

Android 13 (API level 33) introduced 2 new options, fullFast and normalFast. These are the same as full and normal, but use faster algorithm for better performance.

This feature is relevant to languages written without spaces between words, such as Japanese and Chinese. This particular demo works only when the device locale is set to Japanese.

Android 13 (API level 33) introduced the android:lineBreakWordStyle attribute to TextView. Set this attribute to "phrase", and phrases (bunsetsu) in the text will not be separated by line breaks.

Android 13 (API level 33) introduced Conversion Suggestion API that allows apps to access pieces of text before they are committed during a text conversion session. Apps can then use these suggestions to build incremental search queries, etc.

See ConversionEditText.kt and ConversionInputConnection.kt for the detail on how to use the API.

License

Copyright 2023 The Android Open Source Project
 
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.