I need text size for multiple screen(For example large screen , small screen , normal screen ,x-large screen etc..),I already search Google also,but can't fine correct solution.Any one help me.
5 Answers
Use sp
as units for font sizes on android. This will ensure that the font appears approximately the same size on all different screen sizes or resolutions.
Using sp
also ensures that it respects user's preference for screen font sizes.
you'll find tons of answers on so about why you should use sp read this and this
You should not use
android:textSize in 30sp,30dp numeric formats
Choose yourself from following
1st Method:
Instead let android OS analyse your screen size and use following:
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAppearance="?android:attr/textAppearanceSmall"
2nd Method:
define different layout for different screen sizes
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size with small text
res/layout-large/my_layout.xml // layout for large screen size with larger text
res/layout-xlarge/my_layout.xml // layout for extra large screen size with even larger text
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
and sample for layout is :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">18sp</dimen>
</resources>

- 699
- 1
- 10
- 25
Create dimens in values folder like values,values-large,values-xlarge,..and change the size based on screen size by declaring 18sp,20sp,24sp,..You have to use SP(Scaled Pixel)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">18sp</dimen>
</resources>
You need to create layout files for different screen density separately. Thats the way even Google suggests to do.

- 8,250
- 3
- 39
- 71
-
u have any example link.. – saravanan Feb 26 '14 at 06:19
-
this link will give you clear idea : http://developer.android.com/guide/practices/screens_support.html. – Sushil Feb 26 '14 at 06:20
-
also this one: http://developer.android.com/training/multiscreen/index.html – Sushil Feb 26 '14 at 06:21
-
yeah.. i checked dude.. but now i used values-large in side folder dimens.xml. like that.. its better for give text size right? – saravanan Feb 26 '14 at 06:42
-
yes even that way it will work and if you only requirement is Textsize, you can go with this approach. – Sushil Feb 26 '14 at 07:43
-
yes.. thanks. i have another doubt..i need default text size for small screen,larger screen,normal screen.u have any idea about that. – saravanan Feb 26 '14 at 07:54
-
This link will give you the values: http://developer.android.com/design/style/iconography.html. – Sushil Feb 26 '14 at 08:00
-
above link..only for image icon size,action bar icon..i need textsize dude. – saravanan Feb 26 '14 at 08:02
-
1There is no specific textsize for different screen resolution. Only thing you need to take care is use the sp unit. (which is the same as dp, but for fonts) This will ensure that the size is scales based on dots-per-inch (dpi). – Sushil Feb 26 '14 at 08:19
-
ok thanks.i will check.. thanks for replay. – saravanan Feb 26 '14 at 09:29
1) Instead using px use sp for text size for example android:TextSize:20sp Sp = scaled pixels it will scale the pixel of the text according to device dimension
2) You can use style.xml and it can be defined for different resolution and version

- 833
- 6
- 15