Set the default text size to a given unit and value. See TypedValue for the possible dimension units.
Related XML Attributes: android:textSize
Parameters:
unit - The desired dimension unit.
size - The desired size in the given units.
Size of the text. Recommended dimension type for text is "COMPLEX_UNIT_SP".
1. Add a EditText in the main.xml file or Instantiate a new EditText object named myEditText.
2. Add the below line to the import section.
import android.util.TypedValue;
2. In the MainActivity.java file, add the code below. This will set the TypedValue to SP, and the size to 48.
myEditText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 48);
3. Compile and run!
COMPLEX_UNIT_DIP - value is Device Independent Pixels
COMPLEX_UNIT_IN - value is in inches
COMPLEX_UNIT_MM - value is in millimeters
COMPLEX_UNIT_PT - value is in points
COMPLEX_UNIT_PX - value is raw pixels
COMPLEX_UNIT_SP - value is a scaled pixel
Resources:
http://developer.android.com/reference/android/widget/TextView.html#setTextSize(int, float)http://developer.android.com/reference/android/R.attr.html#textSize
http://developer.android.com/reference/android/util/TypedValue.html
http://alvinalexander.com/java/jwarehouse/android/core/java/android/content/res/Resources.java.shtml
http://stackoverflow.com/questions/9494037/how-to-set-text-size-of-textview-dynamically-for-diffrent-screens