Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining user font size selection

I have an Android app that needs some adjustment if the user sets their font size to extra large (via Settings -> Display -> Font size in 4.0 and higher).

Is there a simple way for me to tell what the user's font size preference is

Updated:
in my layout.xml I have lines similar to to setup a button

android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:typeface="sans"

Notice that I'm not setting the font size directly. This layout works and looks good in all cases, except for the Extra Large setting. In that case, due to space limitations, it causes the button's text to wrap to 2 lines.

My goal is to make a slight wording change in the case of Extra Large so that it doesn't wrap

like image 546
Noah Avatar asked Dec 23 '12 02:12

Noah


People also ask

How do I choose the right font size?

As always, it's best to pick a size for your body font first. Make sure it's large enough to read easily at an arm's length, but not too large—you don't want it to overwhelm the page. A good rule of thumb or body font size is 10-14 pt for print, 14-18 pt for screen.

How many different font sizes should I use?

1. Keep The Number of Fonts Used At a Minimum. Using more than 3 different fonts makes a website look unstructured and unprofessional. Keep in mind that too many type sizes and styles at once can also wreck any layout.

What are the three ways to specify the size of a font?

The font-size property is specified in one of the following ways: As one of the absolute-size, relative-size or math keywords. As a <length> or a <percentage> , relative to the element's font size.


1 Answers

There's a FONT_SCALE parameter you should be able to query the system for. I haven't used it myself, but I imagine retrieving its value would look somewhat like this:

float fontScale = Settings.System.getFloat(context.getContentResolver(), Settings.System.FONT_SCALE)

However, I'd also like to point out that usually you shouldn't be dealing with this value directly. In stead, use sp units for textual content so that you don't have to worry about adjusting to user-preferred font sizes yourself, but rather let the system handle that.

Also refer to: Why should we use sp for font sizes in Android?

like image 151
MH. Avatar answered Oct 14 '22 08:10

MH.