banner



How To Change Text Size Android Studio

Read Time: 4 mins Languages:

Android device screens come in all shapes and sizes. Android developers often include text in their applications that needs to be readable, regardless of what device the application is running on. By using some simple methods, developers tin can write i application whose text volition display reasonably well for all sorts of devices, including supporting the user's own text size preferences, with picayune extra work.

In this quick tutorial, we will talk over some of the steps that developers tin can take to brand the text in their applications articulate and readable, as well every bit flexible enough to work on a diversity of screen types and beyond multiple user brandish settings.


How Users Can Configure Font Settings

Some users have swell eyesight and others literally nearly blind. The Android operating organisation recognizes this fact and provides accessibility features to allow the device text font size to be scaled based on the user's preference.

To alter the font settings on the device, launch the Settings application, then choose Brandish, Font Size. The user font preference can be ready to brand text 1 of four font size settings (Small, Normal, Big, and Huge), as shown in Figure 1.

Android SDK Figure 1 Android SDK Figure 1 Android SDK Figure 1


Using Dynamic Font Sizes

When you want your text to be flexible, based on the user preferences, defne text font sizes using SP (scalable point) units. The Android platform allows dimensional values to be divers in a multifariousness of ways. When it comes to text sizes, you will desire to use density-independent units like DP (device-independent pixels) and SP. The SP unit is perfect for text sizes, as it is sensitive to the user's brandish settings.

Here's an case of a TextView that defines its size in terms of SP units:

When it comes to title or heading text, and not text in a free flowing text box, you may not want the user to be able to control the size of the text. In this instance, you'd use the DP unit, equally it scales in pixels with the density of the device, but not with user settings.


Using Fixed Pixel Sizes

When you don't want your text to calibration no matter what, use absolute pixel sizes with the px unit. In that location may be some situations when you do not want your text to scale or alter size. While this is discouraged, as it may make font sizes unreadable on some devices, here'southward how y'all can practise it if you lot have a good reason for doing so. But use one of the accented units, such equally the PX (pixels).

Here's an example of a TextView that defines its size in terms of PX units. The text displayed past this command volition not scale based on the user's preferences or other factors.


Using Standard System Font Sizes

The Android platform defines a set of relative font size styles that you can apply in your applications: Small, Medium, and Big. These font sizes are built upon the SP unit of measurement blazon, and then they will scale with user preferences.

The post-obit XML defines three TextView controls, one that volition exist displayed using the Small font, one in the Medium font, and the third in the Large font size.

Now allow'southward pull everything together and show you what all these different TextView controls would await like on an Ice Foam Sandwich-style device. In the beginning effigy, the user has a Normal font preference, and in the 2d effigy, the user has a Huge font preference. Annotation how the TextView controls display under these weather.

TextView Controls with Various Text Sizes, User Preference for Normal Font Size<br />  TextView Controls with Various Text Sizes, User Preference for Normal Font Size<br />  TextView Controls with Various Text Sizes, User Preference for Normal Font Size<br />

 TextView Controls with Various Text Sizes, User Preference for Huge Font Size  TextView Controls with Various Text Sizes, User Preference for Huge Font Size  TextView Controls with Various Text Sizes, User Preference for Huge Font Size


Decision

Android devices come in all shapes and sizes and Android users accept different needs in terms of application accessibility, such as the need for larger font sizes. Considering of the screen limitations, applications that use text demand to take some steps to keep typography readable and flexible for unlike screens. To start, make certain that your awarding uses scale-independent pixel units (SP), but understand that this font size tin change pretty drastically based upon user preferences.


About the Authors

Mobile developers Lauren Darcey and Shane Conder take coauthored several books on Android development: an in-depth programming book entitled Android Wireless Application Development, Second Edition and Sams Teach Yourself Android Awarding Development in 24 Hours, 2d Edition. When not writing, they spend their fourth dimension developing mobile software at their company and providing consulting services. They can be reached at via email to androidwirelessdev+mt@gmail.com, via their blog at androidbook.blogspot.com, and on Twitter @androidwireless.

Need More Assistance Writing Android Apps? Check out our Latest Books and Resource!

Buy Android Wireless Application Development, 2nd Edition Buy Sam's Teach Yourself Android Application Development in 24 Hours, Second Edition  Mamlambo code at Code Canyon

Source: https://code.tutsplus.com/tutorials/android-user-interface-design-basic-font-sizes--mobile-11194

Posted by: dejesuswhind1980.blogspot.com

0 Response to "How To Change Text Size Android Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel