2

I have my app running well as per design when the font size is at "Normal" on Settings->Display->FontSize.

When i change the font size to Small/Large entire content is mashed up. My app is content intensive and this is badly effecting the app.

Lets say, action bar title is like "Privacy and Settings". The title runs off the bounds/ellipsizes when font size is set to "Large" in System Settings. The listview contents look pathetic.

Is there a way to make sure that the change in Settings->Fonts doesn't effect our app?

Flipboard app does that.

Ramesh
  • 1,311
  • 1
  • 11
  • 19
  • 1
    You do realize that the exact users who up their default font size are the people who cannot read the smaller print and therefore have changed it on purpose? – ianhanniballake Feb 04 '14 at 07:20
  • 1
    Yes i do agree that the settings is for users benefit. But thats the requirement. – Ramesh Feb 04 '14 at 09:04

4 Answers4

4

I finally got the solution. Google strictly recommends to use "sp" for fonts. However, if you do not want the text to be scaled based on user font settings, use "dp". The font size will not change in a given device if you go to settings->fonts. Your UI will remain just like you designed it for.

Thanks Aswin for your inputs. And thanks to Joseph Earl for answering question at Android sp vs dp texts - what would adjust the 'scale' and what is the philosophy of support

Community
  • 1
  • 1
Ramesh
  • 1,311
  • 1
  • 11
  • 19
3

It is best to follow what Google recommends i.e to use 'sp' instead of 'dp'. Here is an updated solution which helped me - Solution

 //in base activity add this code.
public  void adjustFontScale( Configuration configuration) {

    configuration.fontScale = (float) 1.0;
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    metrics.scaledDensity = configuration.fontScale * metrics.density;
    getBaseContext().getResources().updateConfiguration(configuration, metrics);

}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    adjustFontScale( getResources().getConfiguration());
}  
Sathish
  • 31
  • 4
0

Here is how you can do it but I don't recommend it.

float scale = getResources().getConfiguration().fontScale;
// This scale tells you what the font is scaled to.
// So if you want size 16, then set the size as 16/scale
float sizeNeeded = 16.0;
textView.setTextSize(sizeNeeded/scale);

Hope this helps.

Aswin Rajendiran
  • 3,323
  • 1
  • 18
  • 17
  • I read it like, I should customize Textview and override setTextSize and add this scaling calculation there. Use this for all the textviews used in the application. – Ramesh Feb 04 '14 at 08:31
0

use dp or dip instead of sp in textSize

Waqar Ahmed
  • 4,682
  • 1
  • 19
  • 38