How to set the font size in Android

Source: Internet
Author: User

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:

  1. <TextView
  2. android:id="@+id/textview4"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:text="Sample text-26sp"
  6. 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.

      1. <TextView
      2. android:id="@+id/textview5"
      3. android:layout_width="wrap_content"
      4. android:layout_height="wrap_content"
      5. android:text="Sample text-fixed Pixels"
      6. 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.

  1. <TextView
  2. android:id="@+id/textview1"
  3. style="@android: Style/textappearance.small"
  4. android:layout_width="wrap_content"
  5. android:layout_height="wrap_content"
  6. android:text="Sample text-small" />
  7. <TextView
  8. android:id="@+id/textview2"
  9. style="@android: Style/textappearance.medium"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:text="Sample text-medium" />
  13. <TextView
  14. android:id="@+id/textview3"
  15. style="@android: Style/textappearance.large"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. 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.

Original link http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-basic-font-sizes/

How to set the font size in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.