1

How do we change the textSize based on Resolution density?

I have found several ways on SO, but all of them usng java code to do that.

I however need a java free approach because I have someplaces where I set a textSize on XML and some on Java code.

In xml, I do this

        android:textSize="@dimen/FONT_SIZE_SMALL"

however sometimes I need to set it via java code.

        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.FONT_SIZE_SMALL);

Any ideas please? is it doable?

JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
  • http://stackoverflow.com/questions/16706076/drawable-folder-for-different-resolution-and-application-icon-size – Amit Vaghela Jan 21 '16 at 11:57
  • 2
    Possible duplicate of [Text size with different resolution](http://stackoverflow.com/questions/12620343/text-size-with-different-resolution) – Amit Vaghela Jan 21 '16 at 11:59

2 Answers2

0

Use textSize in sp unit in xml. It will adjust to all resolutions.

Hope this helps.

UPDATE Please also refer to Text size with different resolution which proposes some scaling factors for different resolutions.

Community
  • 1
  • 1
Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46
0

You can declare sizes with the <dimen> tag in dimens.xml in resolution specific values folder.
eg

<dimen name="my_text_view_size">12sp</dimen>

You can have multiple value files for different resolutions and can assign different values for the same constant for each resolution. then assign the constant to textsize.

check this for more details https://stackoverflow.com/a/16910589/3329488

Community
  • 1
  • 1
Mo1989
  • 2,374
  • 1
  • 15
  • 17