Andoird User Interface Design Getting Started Guide: Set the font size

Source: Internet
Author: User

Tutorial details

  • Technical Application: AndroidOS/Android SDK

  • Difficulty: simple

  • Expected completion time: 15 minutes

BKJIA: In this article, we will introduce some simple processing methods to help developers easily compile application text solutions that can respond to various device models, you can also customize the text size. Don't worry, there is no difficulty in the whole process. As long as you follow the instructions step by step, you no longer have to worry about adjusting the display effect.

In this getting started tutorial, we will discuss some practical steps to guide developers to ensure that the text is clear and easy to read with sufficient flexibility, at the same time, our products can adapt to a variety of screen types and various user display settings.

How to configure font settings as needed

First of all, it should be emphasized that some users may have visual impairment or even almost blind, and they cannot read the text in general size smoothly. The Android operating system is aware of these situations and provides a set of display auxiliary functions, allowing users to freely scale the text font size in the device according to their usage habits.

To modify the font settings on the device, enable the "set" application and select "font size" under "display ". You can choose a suitable text font size from the four preset text font sizes of the device. The options are small, normal, large, and super large. For details, see Figure 1.

Use Dynamic font size

If you want your app text to be flexibly adjusted based on user preferences, you need to use SP to zoom in.) The Unit defines the text font size. The Android platform allows us to assign values to the dimensions of various display elements in various ways. In terms of text size, we generally recommend using pixels such as DP that are not related to devices) and SP to separately set the display density. The SP unit performs the best in terms of text size, because it can adjust the actual effect completely according to the user's display settings.

The following content uses TextView (text display) to define the font size in the SP unit:

 
 
  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 terms of title, first line text, or scroll text box, we often do not want user preferences to affect the display effect. In this case, you should try the DP unit because it fully adjusts the display according to the pixel density of the device, and does not involve any user preference settings.

Fixed pixel size

If you want your application text to be of the same size under any circumstances, the fixed pixel size function in PX Unit will greatly help you. Although sometimes this will make the default font size difficult to read on some devices, if you have good reasons to stick to this, it is necessary to disable text content scaling or size change. In this case, you may wish to use the absolute size value to design the font size, for example, specify the number of pixels displayed for the text.

In the text box below, we use the pixel PX Unit for short to set a fixed size for the font. In this way, the text content is displayed in strict accordance with our definition, without being 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 set of general font size solutions that can be applied directly to our applications: small, medium, and large options can basically meet the needs of various users. These font sizes are configured on the basis of the SP unit, so they will change with the user's preference settings.

The following XML defines three types of text box control, one is to display small fonts, one is to display the font, the third is to display 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 content mentioned above and look at the actual display of the text box on the "ice cream sandwich" Android device. First, let's look at the first figure. The user selects a common font in preference settings. In the second figure, the user selects a large font in preference settings. Note how the text box function controls the display effect in different settings.

Summary

Android devices have different sizes and shapes. Therefore, Android users must set specific requirements for fonts in applications based on their device models. Due to the inherent limitations of the screen size, developers must take appropriate measures in the application to ensure that the text content has an ideal readability and flexible typographical effect in any model. The first step is to ensure that your applications use a pixel-based size setting solution that is completely independent from devices, however, do not forget the huge or unexpected impact that user settings will bring to the actual display effect.

BKJIA translations are not permitted to be reprinted. For reposted by the media partners, please indicate the source, author, and BKJIA translator !]

Related Article

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.