Share Coding

Tutorials, Problems, Stuffs …

Set/Get text size on Android

From android developers docs: http://developer.android.com/reference/android/widget/TextView.html

public float getTextSize () – Since: API Level 1
Returns the size (in pixels) of the default text size in this TextView.


public void setTextSize (float size) – Since: API Level 1
Set the default text size to the given value, interpreted as “scaled pixel” units. This size is adjusted based on the current density and user font size preference.


To sure the value from getTextSize() and setTextSize(size), we can set the unit by using:

setTextSize(int unit, int size):

TypedValue.COMPLEX_UNIT_PX : Pixels
TypedValue.COMPLEX_UNIT_SP : Scaled Pixels
TypedValue.COMPLEX_UNIT_DIP : Device Independent Pixels

textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, 12);
float size = textview.getTextSize();

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: