-1

I'm new from android, my question is how can I force the font size like 12sp when showing in different android phone?

<Button
   android:id="@+id/btn"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:padding="8dp"
   android:text="hello world"
   android:textSize="@dimen/btn_text"/>
loalexzzzz
  • 463
  • 1
  • 7
  • 16

1 Answers1

1

Create multiple values folders, one for each screen size you want to support. ( values, values-large, values-xlarge and so on).

In every values folder you will include a dimens.xml with the dimensions you wish to use when the screen size is the same as this values folder.

And then your code will work fine.

android:textSize="@dimen/btn_text" will make your button text, a different size if the screen is normal, or large and so on.

  • thanks for your answer anyway, it should be use dp instead of sp https://stackoverflow.com/questions/23981260/should-use-sp-instead-of-dp-for-text-sizes – loalexzzzz Oct 19 '18 at 13:57