'Android button and the size of text

I have a layout with a few buttons that takes the space of the entire layout using weight properties. Each button has some text on it with a fixed size which is set by android:textSize="30dp" so on a screen size of a small mobile device (A phone) the text's size if about the size of the button. But on a large device (A tablet) the button size expands yet the text size remains the same (30dp).

I want the button size and text size ratio to be maintained in every resolution, can it be done using the layout XML code? I would like to avoid doing it programmatically.



Solution 1:[1]

text size should be mentioned in sp, not in dp try like this

 android:textSize="30sp"

Size of the text. Recommended dimension type for text is "sp" for scaled-pixels.

Solution 2:[2]

make different xml layout file for tabs and phone and try this for button

android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" 

Solution 3:[3]

you can fix the size of buttons by giving weight and for the text of a button you can do this to auto size them:

android:autoSizeTextType="uniform"
android:autoSizeMaxTextSize="24sp"
android:autoSizeMinTextSize="20sp"

Set the min and max size what you need and put these codes inside a button body:)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RajaReddy PolamReddy
Solution 2 EstevaoLuis
Solution 3 Eshaqi