- The Android/Material Design Font Size Guidelines
- Android Mobile Typography Guidelines
- Titles
- Body Text
- List Items
- Form Controls
- Desktop Material Design Typography Guidelines
- Watch me do a UI project step-by-step
- Watch me do a UI project step-by-step
- 400+ Android & Flutter Code
- Saturday, January 3, 2015
- How to change TextView font size in android
- Making the most of TextView auto-sizing on Android
- Dynamically adjusting the size of text on Android with a simple API
- When is this needed? 🤔
- The basics 🔤
- Default auto-sizing 1️⃣
- In XML:
- Programmatically:
- Granular auto-sizing 2️⃣
- In XML:
- Programmatically:
- Preset auto-sizing 3️⃣
- In XML:
- Programmatically:
- Pro-tips and gotchas 🤓
- Mixing value types:
- Auto-sizing to a single line:
- Performance:
- Making the most of TextView auto-sizing on Android
- Dynamically adjusting the size of text on Android with a simple API
- When is this needed? 🤔
- The basics 🔤
- Default auto-sizing 1️⃣
- In XML:
- Programmatically:
- Granular auto-sizing 2️⃣
- In XML:
- Programmatically:
- Preset auto-sizing 3️⃣
- In XML:
- Programmatically:
- Pro-tips and gotchas 🤓
- Mixing value types:
- Auto-sizing to a single line:
- Performance:
The Android/Material Design Font Size Guidelines
Erik D. Kennedy В· Published Apr 23, 2018
You’re reading Font Sizes in UI Design: The Complete Guide. Quickly navigate to other chapters: Intro · iOS · Android · Web · Principles
So you’re designing an app in the Material Design style and want to know (roughly) what font size to use? Great. You’ve come to the right place.
All font sizes listed below refer to Roboto. Other fonts may appear bigger or smaller, even using the same size. The units I use in this section are “sp”. It’s pronounced “sips”, and it stands for scaleable pixels. But, as a designer, all you need to know is it’s the number you type into the font size box when you’re designing (for the nitty-gritty on “px”, “pt”, “sp”, and “dp”, see here).
Android Mobile Typography Guidelines
Here’s a quick summary of styles. See below for visual reference and more in-depth guidelines.
Element | Sizing | Notes |
---|---|---|
Page titles | 20sp | |
Paragraph text | 14sp | |
List titles | 14sp | Show importance using medium weight |
List item titles, Important text snippets | 16sp | |
Secondary text, Captions | 14sp | Use lighter color to show lowered importance |
Buttons, Tabs | 14sp | Medium weight |
Text inputs | 16sp |
Now let’s go through element-by-element with (a) visuals and (b) notes on how Google deftly wields these font styles. No joke, folks. I hope you read this section and think “Whoever came up with the Material Design font sizes is one smart cookie” – I sure think so, anyhow.
Titles
Titles on mobile Material Design apps are 20sp.
Body Text
The body text size in Material Design is 14sp. You should think of this as the normal font size, and basically everything else a variation on it.
For instance, while 14sp is the default text size when the text can be quite long, when there’s only a small modal with a bit of text, it’s 16sp!
Notice that it’s a bit lighter to make up for this size boost. This will be a recurring theme in Material Design styles.
List Items
Many simple lists will show each item at 16sp.
In fact, this is the default “list item” size in Material Design.
This was a surprise to me – after all, a list of simple items feels a lot like body text. Why would it be bigger? I think of it like this: the importance per word is much higher than body text. Therefore, it should be larger.
Also notice that having larger list item names means you can have a clear contrast between the list item title and a secondary description, which is both smaller and lighter.
But denser lists, like those on sidebars, are 14sp – and one weight bolder to compensate (this is a bit like the larger modal font size also being lighter to compensate.
Form Controls
Let’s look at buttons and inputs now.
The only surprise here, in my opinion, is that text inputs are size 16sp. Why not the default body size? Because the importance per word is higher than default body text, and unlike the button (which does have 14sp text), it’s weird to have a textbox with medium or bold-weight text.
Desktop Material Design Typography Guidelines
Even though all examples I’ve shown above are from mobile apps, the font sizes vary only a little on tablet and desktop apps. Here is a summary of the typographic changes, again, as provided by Google:
Style | Mobile/tablet Properties | Desktop Properties |
---|---|---|
Subheader List item title | Regular 16sp | Regular 15sp |
Body | Regular 14sp | Regular 13sp |
“Body 2” Menu items List titles | Medium 14sp | Medium 13sp |
If you’re designing a Material app for large screens, it also might be worth reviewing the desktop web section of the next chapter.
Watch me do a UI project
step-by-step
I’ll walk you through every part of a UI project — just like I’ve done for everyone from Fortune 100 companies to Y-Combinator startups.
Exclusive design tutorials. Over 50,000 subscribed. One-click unsubscribe.
Watch me do a UI project step-by-step
I’ll walk you through every part of a UI project — just like I’ve done for everyone from Fortune 100 companies to Y-Combinator startups.
Success! Now check your email to confirm your subscription.
Exclusive design tutorials. Over 50,000 subscribed. One-click unsubscribe.
Источник
400+ Android & Flutter Code
Example code for android + flutter app developers.
Saturday, January 3, 2015
How to change TextView font size in android
TextView widget display text on android application. we can set or change TextView font size statically by declarative syntax in xml layout file or programmatically at run time in java file. even we can use an xml file source to define font size.
the following example code demonstrate us how can we define TextView font size in xml layout file and how can we uses dimens.xml to reference font size. in this example we did not changes any coding in java file, so here we only include the layout xml file and dimens.xml file.
Dimension
we defined dimension value in xml layout file as example 50sp, 20pt, 30dp. dimension is specified with a number followed by a unit of measure. android supported the following units of measure, those are dp, sp, pt, px, mm, in.
dp means Density-independent-Pixels. this is an abstract unit that is based on the physical density of the screen.
sp means Scale-independent-Pixels. SP as like dp but it is also scaled by the user’s font size preference. Sp is recommended unit for measure.
pt means Points — 1/72 of an inch based on the physical size of screen. px describe Pixels which corresponds to actual pixels on the screen. mm is Millimeters which is based on the physical size of the screen. in describe inches which also based on the physical size of the screen.
Источник
Making the most of TextView auto-sizing on Android
Dynamically adjusting the size of text on Android with a simple API
TextView auto-sizing was introduced to the framework with Android 8.0 Oreo (API 26). It offers a simple yet powerful API to solve a particular problem: scaling of text size to fit text bounds.
When is this needed? 🤔
For Android Development, using a fixed textSize , layout_width=»match_parent” and layout_height=»wrap_content” (perhaps inside a scrollable parent) is fairly common practice and suitable for most TextView use cases.
However, consider the case where the width and/or height of the text bounds are fixed and the text needs to adapt to the available space. Examples include a newspaper-style layout, a font selector that needs to show each different font typeface/name on a single-line, etc. The text can’t scroll and we can’t just add a «read more» button. In these scenarios, TextView auto-sizing is precisely what we need.
The basics 🔤
The TextView auto-sizing API is fairly concise. It can be implemented in XML layouts or programmatically. There are three distinct ways of enabling auto-sizing on a TextView , with increasing levels of specificity: Default, Granular and Preset.
At the time of this writing, the chances of anyone having a minSdk of 26 are quite slim. Thankfully, all of the auto-sizing functionality is available in the AndroidX core package (formerly Support Library). The differences to the framework API are minimal:
- Use the app namespace for XML attributes
- Use the functions in TextViewCompat instead those on TextView directly
Note: All of the examples in this post will use the AndroidX implementation.
Before we get going, there are two important points to keep in mind:
- Auto-sizing (as the name would suggest) only adjusts the text size. Other properties (eg. letterSpacing , lineHeight , etc.) are not changed. They do, of course, affect the text layout bounds and thus impact the automatic size chosen for the text.
- It is advised to not use a layout_width or layout_height of «wrap_content» when using TextView auto-sizing, as this may lead to unexpected results. Using a fixed dimension or «match_parent» is fine (or a “0dp” match_constraint if you are using ConstraintLayout ) .
Default auto-sizing 1️⃣
This is the simplest way of enabling TextView auto-sizing. Given the bounds and attributes of a TextView , the text size is adjusted in an attempt to perfectly fit the horizontal and vertical axes.
Note: The granularity dimensions for default auto-sizing are minTextSize = 12sp, maxTextSize = 112sp, and granularity = 1px (see Granular auto-sizing below).
In XML:
Programmatically:
where autoSizeTextType can be:
- TextViewCompat. AUTO_SIZE_TEXT_TYPE_UNIFORM (enabled)
- TextViewCompat. AUTO_SIZE_TEXT_TYPE_NONE (disabled)
Granular auto-sizing 2️⃣
This allows you to define the values used in uniform auto-sizing: the minimum and maximum text sizes as well a dimension for the size of each «step». A «step» is the increase/decrease in size of the text layout bounds. The text size scales uniformly between the minimum and maximum text size after each «step».
In XML:
Programmatically:
where unit is the TypedValue dimension unit of all of the configuration values (eg. TypedValue. COMPLEX_UNIT_SP ).
Preset auto-sizing 3️⃣
This allows you to specify all the possible values used for auto-sizing. The most appropriate text size will be picked from these values to fit the text bounds.
In XML:
Add the preset sizes to res/values/arrays.xml:
Programmatically:
where unit is the TypedValue dimension unit of the preset size values in the array.
Pro-tips and gotchas 🤓
Mixing value types:
You may have noticed that the programmatic versions of granular and preset auto-sizing could be limiting: the TypedValue unit in these functions applies to all of the supplied auto-sizing values. If you want to mix types (eg. PX and SP) then you need to do so in XML.
Auto-sizing to a single line:
You may be required to restrict auto-sized text to a single line. You can set the lines or maxLines TextView layout attributes to «1» (or use the programmatic equivalent). You may also need to adjust the granular autoSizeMinTextSize , as single-line text will be clipped if the minimum text size is reached but the width still exceeds that of the layout bounds.
Performance:
For performance optimization, one might assume that using preset auto-sizing is the best option. In reality, granular text sizes are precomputed given the minimum, maximum and step values and the difference is negligible.
I hope this post has provided some insight into TextView auto-sizing and how best to make use of it. If you have any questions, thoughts or suggestions then I’d love to hear from you!
Источник
Making the most of TextView auto-sizing on Android
Dynamically adjusting the size of text on Android with a simple API
TextView auto-sizing was introduced to the framework with Android 8.0 Oreo (API 26). It offers a simple yet powerful API to solve a particular problem: scaling of text size to fit text bounds.
When is this needed? 🤔
For Android Development, using a fixed textSize , layout_width=»match_parent” and layout_height=»wrap_content” (perhaps inside a scrollable parent) is fairly common practice and suitable for most TextView use cases.
However, consider the case where the width and/or height of the text bounds are fixed and the text needs to adapt to the available space. Examples include a newspaper-style layout, a font selector that needs to show each different font typeface/name on a single-line, etc. The text can’t scroll and we can’t just add a «read more» button. In these scenarios, TextView auto-sizing is precisely what we need.
The basics 🔤
The TextView auto-sizing API is fairly concise. It can be implemented in XML layouts or programmatically. There are three distinct ways of enabling auto-sizing on a TextView , with increasing levels of specificity: Default, Granular and Preset.
At the time of this writing, the chances of anyone having a minSdk of 26 are quite slim. Thankfully, all of the auto-sizing functionality is available in the AndroidX core package (formerly Support Library). The differences to the framework API are minimal:
- Use the app namespace for XML attributes
- Use the functions in TextViewCompat instead those on TextView directly
Note: All of the examples in this post will use the AndroidX implementation.
Before we get going, there are two important points to keep in mind:
- Auto-sizing (as the name would suggest) only adjusts the text size. Other properties (eg. letterSpacing , lineHeight , etc.) are not changed. They do, of course, affect the text layout bounds and thus impact the automatic size chosen for the text.
- It is advised to not use a layout_width or layout_height of «wrap_content» when using TextView auto-sizing, as this may lead to unexpected results. Using a fixed dimension or «match_parent» is fine (or a “0dp” match_constraint if you are using ConstraintLayout ) .
Default auto-sizing 1️⃣
This is the simplest way of enabling TextView auto-sizing. Given the bounds and attributes of a TextView , the text size is adjusted in an attempt to perfectly fit the horizontal and vertical axes.
Note: The granularity dimensions for default auto-sizing are minTextSize = 12sp, maxTextSize = 112sp, and granularity = 1px (see Granular auto-sizing below).
In XML:
Programmatically:
where autoSizeTextType can be:
- TextViewCompat. AUTO_SIZE_TEXT_TYPE_UNIFORM (enabled)
- TextViewCompat. AUTO_SIZE_TEXT_TYPE_NONE (disabled)
Granular auto-sizing 2️⃣
This allows you to define the values used in uniform auto-sizing: the minimum and maximum text sizes as well a dimension for the size of each «step». A «step» is the increase/decrease in size of the text layout bounds. The text size scales uniformly between the minimum and maximum text size after each «step».
In XML:
Programmatically:
where unit is the TypedValue dimension unit of all of the configuration values (eg. TypedValue. COMPLEX_UNIT_SP ).
Preset auto-sizing 3️⃣
This allows you to specify all the possible values used for auto-sizing. The most appropriate text size will be picked from these values to fit the text bounds.
In XML:
Add the preset sizes to res/values/arrays.xml:
Programmatically:
where unit is the TypedValue dimension unit of the preset size values in the array.
Pro-tips and gotchas 🤓
Mixing value types:
You may have noticed that the programmatic versions of granular and preset auto-sizing could be limiting: the TypedValue unit in these functions applies to all of the supplied auto-sizing values. If you want to mix types (eg. PX and SP) then you need to do so in XML.
Auto-sizing to a single line:
You may be required to restrict auto-sized text to a single line. You can set the lines or maxLines TextView layout attributes to «1» (or use the programmatic equivalent). You may also need to adjust the granular autoSizeMinTextSize , as single-line text will be clipped if the minimum text size is reached but the width still exceeds that of the layout bounds.
Performance:
For performance optimization, one might assume that using preset auto-sizing is the best option. In reality, granular text sizes are precomputed given the minimum, maximum and step values and the difference is negligible.
I hope this post has provided some insight into TextView auto-sizing and how best to make use of it. If you have any questions, thoughts or suggestions then I’d love to hear from you!
Источник