In this article, we'll show you some simple ways to help developers easily write application text schemes that can handle a variety of device models, while providing users with custom text size capabilities. Don't worry, the whole process is not difficult, as long as step by step according to the guide to operate, we no longer need to adjust the display effect and worry about it.
In this start-up tutorial, we will discuss practical steps to guide developers to be flexible enough to keep text legible and to adapt their products to a variety of screen types and user display settings.
How users configure font settings on Demand
The first thing to emphasize is that some users may be visually impaired or even nearly blind, and they cannot read the text content in general size. The Android operating system is aware of these situations and provides a set of display accessibility features that allow users to freely scale the size of text fonts in their devices according to their own usage habits.
To modify font settings on your device, first enable the Settings app, and then select Font Size under Display. The user can choose the four kinds of text font size in the device preset (including small, normal, large, oversized), as described in Figure I.
Use dynamic font size
If you want your app text to be flexible based on user preferences, you'll need to define the font size of the text using the SP (Scale point) unit. The Android platform allows us to assign values to the dimensions of various display features in various ways. In terms of text size, we generally recommend using such as DP (device independent pixels) and SP to set the display density separately. SP units perform best in terms of text size because they are able to adjust the actual effect exactly as the user's display settings are.
The following is how we define the font size using the TextView (i.e. text display) feature in SP units:
- <textview
- Android:id= "@+id/textview4"
- Android:layout_width= "Wrap_content"
- android:layout_height= "Wrap_content"
- android:text= "Sample text-26sp"
- Android:textsize= "26sp"/>
In the title, the first line of text or scrolling text box, we often do not want users ' preferences to affect the display effect. In such cases, you should try the DP unit, because it adjusts the display exactly based on the pixel density of the device, and does not involve any user preferences.
Use fixed pixel dimensions
The fixed pixel size feature of PX units can be a big help if you want your app text to be the same size in any case. Although sometimes this makes the default font size difficult to read on some devices, it is necessary to disable text content scaling or resizing if you have a good reason to stick to it. In such cases, it may be useful to use absolute size values for font design, such as specifying the number of pixels displayed for text.
In the text box below, we use pixels (px) units to set a fixed size for the font. In this way, the text content is displayed in strict accordance with our definition, and is not affected by user preferences or other interference factors.
- <textview
- Android:id= "@+id/textview5"
- Android:layout_width= "Wrap_content"
- android:layout_height= "Wrap_content"
- android:text= "Sample text-fixed Pixels"
- Android:textsize= "14px"/>
Use standard system font size
The Android platform defines a universally applicable font size scheme that we can apply directly to our own applications: small, Medium, and junior options are basically designed to meet the needs of a wide range of users. These font sizes are configured on an SP unit basis and are therefore subject to change as the user's preferences are set.
The following XML defines three types of text box controls, one that displays small fonts, one display font, and a third that displays large fonts.
- <textview
- Android:id= "@+id/textview1"
- Style= "@android: Style/textappearance.small"
- Android:layout_width= "Wrap_content"
- android:layout_height= "Wrap_content"
- android:text= "Sample text-small"/>
- <textview
- Android:id= "@+id/textview2"
- Style= "@android: Style/textappearance.medium"
- Android:layout_width= "Wrap_content"
- android:layout_height= "Wrap_content"
- android:text= "Sample text-medium"/>
- <textview
- Android:id= "@+id/textview3"
- Style= "@android: Style/textappearance.large"
- Android:layout_width= "Wrap_content"
- android:layout_height= "Wrap_content"
- android:text= "Sample text-large"/>
Now let's combine the above mentioned content and look at the actual display of the text box on the "Ice Cream Sandwich" version of Android device. First look at the first picture, the user selects the normal font in the preferences, and in the second image, the user selects the oversized font in preferences. Notice how the text box function controls the display effect under different settings.
Summarize
Android devices are available in a variety of sizes and shapes, so Android users are bound to make specific demands on the fonts in their applications based on their device model. Due to the inherent limitations of screen size, developers must take appropriate action in the application to ensure that text content is ideal for readability and flexible typography in any model. The first step is to make sure your application uses a pixel-based size setting scheme that is completely independent of the device, but don't forget that the user settings will have a huge or even unintended effect on the actual display.
How to set the font size in Android