I have an Android app that looks absolutely horrible if the user sets their font size to large or extra large (via Settings -> Display -> Font size in Ice Cream Sandwich). It just plain wasn't designed for variable font sizes, and it makes a lot of the text unreadable.
I've seen applications that preserve the font size for most views, so I know that there has to be a way to do this. Is there a simple way for me to tell the application to ignore the user's font size preference? And if there isn't, how would you suggest that I go about calculating the font sizes? If nothing else, is there a way for me to retrieve the user's font size preference?
I think what you want to do is specify your font sizes in "dp" instead of "sp". All sp units take user font size preferences into account when adjusting their size, while dp units only calculate size based on the device's pixel density.
Related
I've been using dp for dimensions and sp for text size for 3 years now, ever since I've started developing apps for Android.
But recently, I've been joined with a couple people that don't believe in dp and sp saying "it doesn't show the same on all devices".
The method they've used is:
When setting the text size, you don't use 24 sp nor 24 dp, you set it as 24% of the screen width or height in pixels. in this way, the text is always the same size in pixels on all devices (including tablets).
How correct/valid is this method? What is the professional way to design? What is the opinion of a professional Android designer to this method?
Don't know how good % can replace dp, but don't use it as a text size.
sp is great because users can resize it by changing their preferred text size in the device settings. Don't take away this possiblity just because it makes your design easier for you.
Accessibility > Design
See this guide for reference: Support different pixel densities
When defining text sizes, however, you should instead use scalable pixels (sp) as your units (but never use sp for layout sizes). The sp unit is the same size as dp, by default, but it resizes based on the user's preferred text size.
Best unit for text is sp and for dimensions best unit is dp.
That is given perfect result of in which you want.
In most of developer use this unit for text and dimensions.
I try for your % but that is not work in my app.
dp stands for density independent pixels. Its goal is, to define a more or less physical dimension. E.g. 48dp are about the size if a finger tip, and that's why tappable icons (e.g. on ActionBar) should have that size.
So for UIs you should always use dp (and sp for texts). It also has the advantage, that you can show more data on a larger screen (e.g. more items in a list are visible etc.).
If you're using % of the screen size, you are doing the exact opposite. On a small device 24% it will be small (physically speaking) on a large tablet it will be large.
Using % might make sense if you're developing a game for example and you want the same image shown on every device, large or small.
DP/SP Does not claim to be the same on all screen sizes but about the same size across screen densities. The reason it is only about the same size is that density is broken up into categories (e.g. mdpi, hdpi, xhdpi...).
You don't want the text to be relative to the screen size because then the text will be really small for devices that have a small screen and really large for devices that have a large screen. Instead you want the font size to be comfortable to read and about the same size on large or small screen. The large screens will just have the advantage of more text on the screen at a time.
In addition as other users have mentioned sp (and apparently now dp) can be scaled based upon user preferences which is really helpful for people with poor eyesight.
While defining a view in android, we use dp for margins, sizes, etc but for text sizes we use sp. sp is also same as dp but for texts. Why can't we use sp for everything then?
I know the difference in between the two. I am asking if sp is a superset of dp, why use dp at all? why not use sp to specifiy all sizes in views?
The reason we can't use sp for everything is that when we increase the font size from settings,we only want the text to resize and not the buttons and other views as well. So we use dp for the rest and just sp for the text.
The sp unit of measurement is used for fonts and is pixel
density dependent in the exact same way that dp is. The extra calculation that an
Android device will take into account when deciding how big your font will be,
based on the value of sp you use, is the user's own font size settings. So, if you test
your app on devices and emulators with normal size fonts, then a user who has a
sight impairment (or just likes big fonts) and has the font setting on large, will see
something different to what you saw during testing.
I have kept my EditText font size as 16sp. However when I change the device font size, the EditText font size also changes. I tried using dp instead of sp which worked but I doubt if it will work well on different screens. How to I keep font size constant using sp as the unit irrespective on device font size and screen density?
You should use dp. The only difference between dp and sp is that dp will ignore the user's text size setting for the device. The result will be that the font size measured in real-world units (points, inches, etc.) will be the same on all devices, regardless of pixel density.
Note that screen size never affects any of this. If you want the text size to be defined in terms of a certain fraction of the screen dimension (e.g., width), there's nothing built into Android's unit system to support that. You'll have to either do the calculation in code (taking into account both screen size in pixels and pixel density) or define the size using alternative resources for different screen sizes.
Hello I am making an android application where I am giving text size is in sp as recommended.
I am setting my font size to 25sp to the TextView. Suppose here if user pick "Large" font of the device from the settings of the device and later update it to "Normal" then my application font also vary according to that.
But Is there any calculation such that I can calculate what would be size of font if it is "Large" and "Normal" ?
Screenshot of the device font settings
Sure, you can get view dimensions, but you do not really need to care in most cases. If you set size in sp then it means you are aware what that unit means and you expect this behaviour. If you do not like fonts size being changed, simply use dp
I am programming application, which will be used on various kinds of resolutions, but let's say, we would keep to the density. For medium, high and low I am setting it's own drawables, but it still doesn's solve my problem, so I am wondering, how to set values dependently on actual pixel screen density in Java code?
In this time I have to in XML set smaller letters and smaller textviews to fit it into low resolution screen, on the other hand, high density screen is used from about 60% and text fields are too small. I am wondering if there is some way how to, during the start of the program, in some If loop find out, what the resolution is and then set layout_height and textSize for items I want.
Thanks
edit: Solved myself - http://developer.android.com/reference/android/util/DisplayMetrics.html
well before moving ahead to set the text size programatically, I recommend you to set the Textsize property's value in dip instead of px. it seems that you have marked the textsize value in px.