Different font sizes for different screen sizes

In my application I must use a smaller font for the medium density devices. Is it possible to specify that?

  • Invalid command line parameter when Android executes
  • Android - Image Picker, Wrong Image
  • Android: how to programmatically set width of ImageView inside TableRow
  • Android & iOS: How to develop for both?
  • Navigation Drawer rendering error in ADT Layout Editor
  • onPrepareActionMode not called when creating ActionMode
  • Related posts:

    Why is adding an OnClickListener inside onBindViewHolder of a RecyclerView.Adapter considered bad pr...
    How do I 'navigate' to an activity that's already running?
    Is there any examples of how to implement full-screen advertisement for android?
    Programmatically select item ListView in Android
    Margin does not impact in “include”
    Using android.view.SurfaceView with a camera on part of the screen
  • Problem to load flv video in webview
  • Copy with clipboard manager that supports old and new android versions?
  • Fixed Button below a scrollable ListView
  • How does Android handle background threads when leaving an Activity?
  • How to highlight a button when is pressed?
  • Button Click Listeners in Android
  • 3 Solutions collect form web for “Different font sizes for different screen sizes”

    You should use styles, then you can have separate folders “values” (default) “values-hdpi” (high density) “values-mdpi” (medium density) and so on and put your style file with correct textSize values in each folder as needed.

    Then, when you are in medium density device it will pick the file in “values-mdpi” folder if exists or in “values” if not, and the same for high density etc…

    This same principle applies to al “res” subfolders (drawables, values, etc…)

    Specify all your fonts using dips (e.g. 14dp) rather than pixels (e.g. 14px) and you won’t need to worry about screen density. Android will scale your fonts (and layout) accordingly.

    Edit: Here’s comparison of sp/dp from the Android docs:

    Density-independent Pixels – an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, so 160dp is always one inch regardless of the screen density. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. You should use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens.

    Scale-independent Pixels – this is like the dp unit, but it is also scaled by the user’s font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user’s preference.

    yes, for implementing an universal app which will be working for all resolution.
    You should configure multiple drawables & corresponding layouts.






    then you can change according to your resolution required for Device.
    Android supports internal configuration for Density factor of various Screen’s resolution.
    the device can take itself as appropriate drawable & corresponding layout.
    you dont need to adjust any line of code in your src files.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.